257. Longest Consecutive Sequence
Medium · Hash Table
Given an unsorted array of integers, return the length of the longest consecutive elements sequence. Your algorithm must run in O(n) time.
Examples
Example 1 Input: nums = [100, 4, 200, 1, 3, 2] Output: 4 Explanation: [1,2,3,4] is the longest consecutive sequence
Constraints
- 0 ≤ n ≤ 10⁵