排序
class Solution {
public:
int longestConsecutive(vector<int>& nums) {
if(nums.empty())return 0;
int n=nums.size();
if(n==1)return 1;
sort(nums.begin(),nums.end());
int out=1,max_n=1;
for(int i=1;i<n;i++){
if(nums[i-1]==nums[i]){
}else if(nums[i-1]+1==nums[i]){
max_n++;
out=max(out,max_n);
}else max_n=1;
}
return out;
}
};