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 085e297 commit 90318a2Copy full SHA for 90318a2
longest-consecutive-sequence/mandoolala.py
@@ -0,0 +1,16 @@
1
+from typing import List
2
+
3
+class Solution:
4
+ def longestConsecutive(self, nums: List[int]) -> int:
5
+ num_set = set(nums)
6
+ longest = 0
7
8
+ for num in nums:
9
+ if num - 1 not in num_set:
10
+ cnt = 1
11
+ next_num = num + 1
12
+ while next_num in num_set:
13
+ cnt += 1
14
+ next_num += 1
15
+ longest = max(longest, cnt)
16
+ return longest
0 commit comments