Skip to content

Instantly share code, notes, and snippets.

@seanbenhur
Created November 3, 2020 12:23
Show Gist options
  • Save seanbenhur/5e5137dc97433b081b832426bc9c9a1e to your computer and use it in GitHub Desktop.
Save seanbenhur/5e5137dc97433b081b832426bc9c9a1e to your computer and use it in GitHub Desktop.
class Solution(object):
def longestConsecutive(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
nums = set(nums)
best = 0
for x in nums:
if x-1 not in nums:
y = x+1
while y in nums:
y += 1
best = max(best,y-x)
return best
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment