Skip to content

Commit 58ce3be

Browse files
committed
adding longestConsecutive
1 parent 0259c41 commit 58ce3be

File tree

1 file changed

+13
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)