```
class Solution:
# @param num, a list of integer
# @return an integer
def longestConsecutive(self, num):
numbers = set(num)
max_len = 0
while numbers:
m = n = numbers.pop()
length = 1
while m-1 in numbers:
numbers.remove(m-1)
m -= 1
length += 1
while n+1 in numbers:
numbers.remove(n+1)
n += 1
length += 1
max_len = max(max_len, length)
return max_len
```

keep trace of the max_len