Longest Consecutive Sequence
Return the length of the longest run of consecutive integer values present in nums. Input order and duplicates do not affect the run. Aim for expected linear time.
Example 1
nums = [9,2,4,3,2,1]4Explanation
1,2,3,4 form a run of four; repeated 2 adds no length and 9 is isolated.
Example 2
nums = []0Explanation
There are no values from which to build a run.
Example 3
nums = [-3,-1,-2,5]3Explanation
-3,-2,-1 form a run of three even though the input is unsorted; 5 is separate.
Constraints
- 0 <= len(nums) <= 100000
- Values are signed 32-bit integers
Function contract
longestConsecutiveArguments: jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 34 cases, on your device.
[9,2,4,3,2,1]