799. 最长连续不重复子序列(双指针板子)
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N], s[N];
signed main(){
int n; 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++]]--;
}
res = max(res, i - j + 1);
}
printf("%d\n", res);
return 0;
}

浙公网安备 33010602011771号