代码
#include<iostream>
using namespace std;
const int N = 100010;
int a[N],f[N];
int main(){
int n; cin >> n;
int ans = 0, j = 1;
for(int i = 1; i <= n; i++){
scanf("%d",&a[i]);//读入该数组
f[a[i]]++;//计数
while(f[a[i]] > 1){//如果计数超过1说明已重复 让j往后走
f[a[j]]--;//针对每一个,减去一,直到减掉重复的
j++;
}
ans = max(ans, i - j + 1);//序列长度计算 i - j + 1
}
cout << ans;
return 0;
}
标签:int,重复子,799,ans,序列,Acwing
From: https://www.cnblogs.com/index-12/p/17279918.html