Skip to content

Commit 05c8def

Browse files
committed
longest-consecutive-sequence
1 parent d35809f commit 05c8def

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def longestConsecutive(self, nums: List[int]) -> int:
3+
num_set = set(nums)
4+
max_length = 0
5+
6+
for num in num_set:
7+
if num - 1 not in num_set:
8+
length = 1
9+
while num + length in num_set:
10+
length += 1
11+
max_length = max(max_length, length)
12+
return max_length

0 commit comments

Comments
 (0)