最长连续序列
解题思路:哈希表
class Solution { public int longestConsecutive(int[] nums) { HashSetset = new HashSet<>(); for(int i:nums) { set.add(i); } int currentNum = 0; int len = 0; int lenMax = 0; for(int i:nums) { if(!set.contains(i-1)) { currentNum = i; len = 1; while(set.contains(++currentNum)) { ++len; } lenMax = Math.max(len, lenMax); } } return lenMax; }}