class Solution {
public:
/**
*
* @param arr int整型vector the array
* @return int整型
*/
int maxLength(vector<int>& arr) {
int res = 0;
std::unordered_map<int, int> hash;
for (int left = 0, right = 0; right < arr.size(); ++right) {
++hash[arr[right]];
while (hash[arr[right]] > 1) {
--hash[arr[left++]];
}
res = std::max(res, right - left + 1);
}
return res;
}
};