Created
November 3, 2020 12:23
-
-
Save seanbenhur/5e5137dc97433b081b832426bc9c9a1e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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