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 e0d479f commit a4268c0Copy full SHA for a4268c0
longest-consecutive-sequence/printjin-gmailcom
@@ -0,0 +1,13 @@
1
+class Solution:
2
+ def longestConsecutive(self, nums):
3
+ num_set = set(nums)
4
+ longest = 0
5
+ for num in num_set:
6
+ if num - 1 not in num_set:
7
+ current = num
8
+ length = 1
9
+ while current + 1 in num_set:
10
+ current += 1
11
+ length += 1
12
+ longest = max(longest, length)
13
+ return longest
0 commit comments