128. Longest Consecutive Sequence
Posted 鸵鸟
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了128. Longest Consecutive Sequence相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章
128. Longest Consecutive Sequence
128. Longest Consecutive Sequence
128. Longest Consecutive Sequence
128. Longest Consecutive Sequence