← 返回 rippling 的题目列表Longest Consecutive Sequence (variation)
类型:online_judge
Problem: Longest Consecutive Integer Sequence
Given an unsorted integer array nums, return the length of the longest sequence of consecutive integers.
A consecutive sequence is of the form [x, x+1, x+2, ...] where adjacent values differ by 1. The elements must all appear in nums, but they do not need to be adjacent in the original array.
Input
One line of integers representing the array nums (space-separated).
Output
A single integer: the length of the longest consecutive sequence.
Constraints
0 <= len(nums) <= 2 * 10^5
-10^9 <= nums[i] <= 10^9
Examples
Example 1 Input:
100 4 200 1 3 2
Output:
4
Example 2 Input:
0 3 7 2 5 8 4 6 0 1
Output:
9
Example
Input
100 4 200 1 3 2
Output
4