class Solution {
public:
/**
*
* @param arr int整型vector the array
* @return int整型
*/
int maxLength(vector<int>& arr) {
// write code here
unordered_map<int,int> hash;
int re = 0;
for(int i =0 ,j = 0; i < arr.size(); i ++)
{
// 用哈希表记录元素是否出现
// 双指针
hash[arr[i]] ++;
// i向后遍历,j向前遍历,遇到有重复元素,向前删除元素,直到没有重复,进行下一步
while(hash[arr[i]] > 1) hash[arr[j++]] --;
// 统计最长无重复的子数组
re= max(re, i - j + 1);
}
return re;
}
};