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 72b43d1 commit 89ac2feCopy full SHA for 89ac2fe
longest-consecutive-sequence/oddong.py
@@ -0,0 +1,17 @@
1
+class Solution:
2
+ def longestConsecutive(self, nums: List[int]) -> int:
3
+ if not nums:
4
+ return 0
5
+
6
+ nums = sorted(set(nums))
7
+ longest_streak = 1
8
+ current_streak = 1
9
10
+ for i in range(1, len(nums)):
11
+ if nums[i] == nums[i - 1] + 1:
12
+ current_streak += 1
13
+ else:
14
+ longest_streak = max(longest_streak, current_streak)
15
16
17
+ return max(longest_streak, current_streak)
0 commit comments