128. 最长连续序列
class Solution {
public int longestConsecutive(int[] nums) {
Set set = new HashSet<>();
for(int x : nums){
set.add(x);
}
int res = 0;
for(int x : set){
//如果set里不包括x - 1
//说明序列从x开始
if(!set.contains(x - 1)){
int y = x;
while(set.contains(y + 1)) y++;
res = Math.max(res, y - x + 1);
}
}
return res;
}
}



