128. 最长连续序列
func longestConsecutive(nums []int) int {
numSet := make(map[int]bool, len(nums))
for _, num := range nums {
numSet[num] = true
}
maxLen := 0
for key := range numSet {
curLen := 1
curKey := key
if !numSet[key - 1] {
for numSet[curKey + 1] {
curLen += 1
curKey += 1
}
}
if curLen > maxLen {
maxLen = curLen
}
}
return maxLen
}