The steps are:

- sort the array
- check the values
- return the result

```
public int longestConsecutive(int[] nums) {
// sort the array
Arrays.sort(nums);
// final result
int res = 1;
// partial result
int tmp = 1;
for(int i = 1; i < nums.length; i++){
// ignore the same num
if(nums[i] == nums[i-1]){
continue;
}
// count the consecutive num
else if(nums[i-1] + 1 == nums[i]){
tmp++;
}
// reset the tmp var and check the max
else {
if(tmp >= res)
res = tmp;
tmp = 1;
}
}
// correct last iteration
if(tmp > res){
res = tmp;
}
return res;
}
```