Description:
Solution:
Sorthing is O(nlogn), so we need a solution for O(n)
if (n - 1) not in numSet, it would be the first start point of sequence.
In while loop, we keep add the length by 1 to see how long the sequence is.
And then, return the longest sequence.
Time Complexity: O(n)
Space Complexity: O(n)
'LeetCode ๐๏ธ > Graph' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
32. Graph Valid Tree (0) | 2023.07.13 |
---|---|
269. Alien Dictionary (0) | 2023.07.11 |
200. Number of Islands (0) | 2023.07.10 |
417. Pacific Atlantic Water Flow (0) | 2023.07.09 |
207. Course Schedule (0) | 2023.07.08 |