Skip to content

Commit 333672a

Browse files
committed
Sync LeetCode submission - Longest Consecutive Sequence (python3)
1 parent 79a57fb commit 333672a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
def longestConsecutive(self, nums: List[int]) -> int:
3+
longest_streak = 0
4+
num_set = set(nums)
5+
6+
for num in num_set:
7+
if num - 1 not in num_set:
8+
current_num = num
9+
current_streak = 1
10+
11+
while current_num + 1 in num_set:
12+
current_num += 1
13+
current_streak += 1
14+
15+
longest_streak = max(longest_streak, current_streak)
16+
17+
return longest_streak

0 commit comments

Comments
 (0)