Prompt: Given a list of integers, return the longest consecutive sequence.
Note: A consecutive sequence is an integer array where [i0,i1,i3, … , in] where ij + 1 = ij+1 .
Example:
Input: nums = [100,4,200,1,3,2]
Output: 4
Explanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4.
Input: nums = [0,3,7,2,5,8,4,6,0,1]
Output: 9
Solution: First, we can sort the array to align all the consecutive elements. Then, we can loop through the array and record the length of all consecutive sequences. Each time we loop, we compare the length of the current consecutive sequence to the longest consecutive sequence.