public int longestConsecutive(int[] nums) {
if(nums==null || nums.length==0){
return 0;
}
HashSet<Integer> set=new HashSet<Integer>();
int len=1;
for(int e:nums){
set.add(e);
}
for(int e:nums){
int left=e-1;
int right=e+1;
int count=1;
while(set.contains(left)){
count++;
set.remove(left);
left--;
}
while(set.contains(right)){
count++;
set.remove(right);
right++;
}
len=Math.max(len,count);
}
return len;
}