import java.util.*; public class Solution { /** * * @param arr int整型一维数组 the array * @return int整型 */ public int maxLength (int[] arr) { // write code here int left =0,right =0; int l = arr.length; int maxLength = 0; HashSet<Integer> set = new HashSet<>(); while(right<l){ if(!set.contains(arr[right])){ set.add(arr[right]); right++; }else{ maxLength = Math.max(maxLength,right-left); while(set.contains(arr[right])){ set.remove(arr[left]); left++; } } } if(left<right){ maxLength = Math.max(maxLength,right-left); } return maxLength; } }