class Solution { public: /** * * @param arr int整型vector the array * @return int整型 */ int maxLength(vector<int>& arr) { // write code here int max_l = 0, curr_l = 0; int n = arr.size(); unordered_map<int,int> mp; for(int i = 0; i < n; i++) { if(!mp.count(arr[i])) { curr_l ++; max_l = max(curr_l, max_l); mp[arr[i]] = i; } else { curr_l = min(curr_l+1, i - mp[arr[i]]); mp[arr[i]] = i; max_l = max(curr_l, max_l); } } return max_l; } };