import java.util.*;

public class Solution { /** * * @param arr int整型一维数组 the array * @return int整型 */ public int maxLength (int[] arr) { // write code here int len = arr.length; int left = 0; int right = 0; int max = 0; Set set = new HashSet<>(); while(right < len){ if(!set.contains(arr[right])){ set.add(arr[right]); max = max > right - left +1 ? max :right - left +1; right++; continue; } // max = max > right - left +1 ? max :right - left +1; while(set.contains(arr[right])){ set.remove(arr[left]); left ++; } set.add(arr[right]); right ++; } return max; } }