`class Solution {

public:

int longestConsecutive(vector<int>& nums) {

if(!nums.size()) return 0;

sort(nums.begin(),nums.end());

int max_length = 1;

int front_length = 1;

for(int i = 1;i<nums.size();i++){

if(nums[i-1]+1==nums[i]){

front_length++;

max_length = max(max_length,front_length);

}

else

front_length = nums[i-1]==nums[i]? front_length:1;

}

```
return max_length;
}
```

};`