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 7f6ea6f commit 7baf829Copy full SHA for 7baf829
longest-consecutive-sequence/jeldo.py
@@ -0,0 +1,13 @@
1
+class Solution:
2
+ # O(n)
3
+ def longestConsecutive(self, nums: list[int]) -> int:
4
+ max_length = 0
5
+ nums_set = set(nums)
6
+ for n in nums_set:
7
+ if n - 1 not in nums_set:
8
+ length = 0
9
+ while n + length in nums_set:
10
+ length += 1
11
+ max_length = max(max_length, length)
12
+
13
+ return max_length
0 commit comments