标签:ons integer pre return ret log public sequence cut
class Solution { public int longestConsecutive(int[] nums) { Set<Integer> set=new HashSet<Integer>(); for(int num:nums) set.add(num); int res=0; for(int num:set) if(!set.contains(num-1)) { int x=num+1; while(set.contains(x)) x++; res=Math.max(x-num,res); } return res; } }
128. Longest Consecutive Sequence
标签:ons integer pre return ret log public sequence cut
原文地址:http://www.cnblogs.com/asuran/p/7624962.html