128. Longest Consecutive Sequence
- turn into set, find element with no previous element in the set, and continue from there
- ensure the number is a start of a sequence
class Solution(object):
def longestConsecutive(self, nums):
numbers = set(nums)
maximum = 0
for num in nums:
if (num - 1) in numbers:
continue
else:
i = num
while i + 1 in numbers:
i = i + 1
maximum = max(maximum, i - num + 1)
return maximum