class Solution {
public:
/**
*
* @param arr int整型vector the array
* @return int整型
*/
int maxLength(vector<int>& arr) {
// write code here
vector<int>ans;
int max=0;
int left=0,right=0;
if(arr.size()==1) return 1;
if(ans.size()==0)
{
ans.push_back(arr[right]);
right++;
}
while(right<arr.size())
{
int data=arr[right];
if(find(ans.begin(),ans.end(),data)==ans.end())
{
ans.push_back(data);
right++;
}
else{
left++;
max=ans.size()>max?ans.size():max;
ans.clear();
for(int i=left;i<right;i++)
ans.push_back(arr[i]);
}
}
return ans.size()>max?ans.size():max;;
}
};