题目描述
https://www.acwing.com/problem/content/description/801/
C++ 代码
#include<iostream>
#include<cstdio>
using namespace std;
int a[100010],s[100010],n;
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
int res=0;
for(int i=1,j=1;i<=n;i++)
{
s[a[i]]++;
while(s[a[i]]>1)
{
s[a[j]]--;
j++;
}
res=max(res,i-j+1);
}
cout<<res;
return 0;
}