LeetCode Note Java 00128:Longest Consecutive Sequence
返回 int Array 中最長的連續數字長度。
題目
Longest Consecutive Sequence Medium
Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence.
You must write an algorithm that runs in O(n) time.
我的解法
- 先排序。
- 再來就數連續相差 1 的數量。
1 | class Solution { |
結果意外的簡單。