We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0711835 commit c2c53acCopy full SHA for c2c53ac
longest-consecutive-sequence/Sung-Heon.py
@@ -0,0 +1,21 @@
1
+class Solution:
2
+ def longestConsecutive(self, nums: List[int]) -> int:
3
+ if not nums:
4
+ return 0
5
+
6
+ num_set = set(nums)
7
+ longest = 0
8
9
+ visited = set()
10
11
+ for num in num_set:
12
+ if num not in visited and num - 1 not in num_set:
13
+ current = num
14
+ current_streak = 0
15
+ while current in num_set:
16
+ visited.add(current)
17
+ current_streak += 1
18
+ current += 1
19
+ longest = max(longest, current_streak)
20
21
+ return longest
0 commit comments