双指针

import java.util.*;


public class Solution {
    /**
     * 
     * @param arr int整型一维数组 the array
     * @return int整型
     */
    public int maxLength (int[] arr) {
        // write code here
        if(arr.length == 0){
            return 0;
        }
        HashMap<Integer,Integer> hm = new HashMap<>();
        int max = 0;
        for(int i = 0 ,j=-1;i < arr.length; i++){
            if(hm.containsKey(arr[i])){
                j = Math.max(j,hm.get(arr[i]));
            }
            hm.put(arr[i],i);
            max = Math.max(max,i-j);
        }
        return max;
    }
}