leetcode
leetcode copied to clipboard
0128-longest-consecutive-sequence.py
for n in nums:
# check if its the start of a sequence
if (n - 1) not in numSet:
length = 1
while (n + length) in numSet:
length += 1
longest = max(length, longest)
If there are duplicates in nums, you repeat work. It's more efficient to do for n in numSet: