package com.lsy.leetcodehot100;import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;public class _Hot3_最长连续序列 {public static int longestConsecutive(int[] nums) {Set<Integer> set = new HashSet<>();for(int num:nums){set.add(num);}int max = 0;for (int num : set) {int current = num;if(!set.contains(current-1)){while(set.contains(current+1)){current++;}}max = Math.max(max,current-num+1);}return max;}public static void main(String[] args) {int[] nums= {1,3,2,0,5,6,9,8,7,3,0,3,5};int max = longestConsecutive(nums);System.out.println(max);}
}