#include<unordered_map> class Solution { public: int maxLength(vector<int>& arr) { unordered_map<int , int> mymap; int i = 0 , Max = INT_MIN; while(i<arr.size()) { mymap.clear(); mymap[arr[i]] = i; int j = i+1; while(j<arr.size()) { if(mymap.count(arr[j])==0)//返回匹配特定键的元素数量 { mymap[arr[j]] = j; } else { i = mymap.at(arr[j]);//访问指定键值的元素 break; } j++; } i++; int temp = mymap.size(); Max = max(Max , temp); } return Max; } };