set
-
[LeetCode] Longest Consecutive Sequence알고리즘 2019. 12. 6. 21:54
문제 Given an unsorted array of integers, find the length of the longest consecutive elements sequence. Your algorithm should run in O(n) complexity. Example: Input: [100, 4, 200, 1, 3, 2] Output: 4 Explanation: The longest consecutive elements sequence is [1, 2, 3, 4]. Therefore its length is 4. Approach 배열이 sorting되어있으면 아주 쉽다. priority queue를 활용한 heap에 배열을 옮겨 담고 하나씩 빼면서 연속인지 아닌지 확인하면 됨 하지만 이 방법은..