Skip to content

Commit 4f2a046

Browse files
Merge pull request #1 from swapnil290502/swapnil290502-patch-1
Create Efficient solution for Longest Consecutive sequence leetcode p…
2 parents c16d2f8 + fc62ed1 commit 4f2a046

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
def longestConsecutive(nums):
2+
nums = set(nums)
3+
best = 0
4+
for x in nums:
5+
if x - 1 not in nums:
6+
y = x + 1
7+
while y in nums:
8+
y += 1
9+
best = max(best, y - x)
10+
return best
11+
12+
nums = [0,3,7,2,5,8,4,6,0,1]
13+
result = longestConsecutive(nums)
14+
print(result)

0 commit comments

Comments
 (0)