LeetCode:128 最长连续序列
class Solution { public int longestConsecutive(int[] nums) { if(nums==null){ return 0; } Arrays.sort(nums); PriorityQueue<Integer> que = new PriorityQueue<Integer>((a,b)->a.compareTo(b)); int len = nums.length; int t=0; int tmp=0; for(int i=0;i<len;i++){ if(que.size()==0){ tmp = nums[0]; que.add(nums[0]); t++; continue; } if(nums[i]==tmp+1){ tmp = nums[i]; que.add(nums[i]); t=Math.max(que.size(),t); } else if(nums[i]==tmp){ continue; } else{ que.clear(); tmp = nums[i]; que.add(nums[i]); } } return t; } }