799. 最长连续不重复子序列
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1000010;
int a[N],s[N];
int n;
int main(){
scanf("%d",&n);
for(int i = 1 ; i <= n ; i ++) scanf("%d",&a[i]);
int res = 0;
for(int i = 0 , j = 0 ; i < n ; i ++){
//j为大循环
s[a[i]]++;
while(j < i && s[a[i]] > 1) s[a[j++]]--;
res = max(res,i-j+1);
}
cout << res;
}
评论区