class Solution {
public:
    /**
     * 
     * @param arr int整型vector the array
     * @return int整型
     */
    int maxLength(vector<int>& arr) {
        // write code here
        int len = arr.size();
        int ret = 0, start = 0;
        map<int, int>mp;
        for (int i = 0; i < len; i++) {
            // 如果找到重复的,开始刷新ret
            if(mp.find(arr[i]) != mp.end()) {
                start = max(start, mp[arr[i]] + 1);
            }
            ret = max(ret, i - start + 1);
            // 更新位置
            mp[arr[i]] = i;
        }
        return ret;
        
    }
};