最长不重复连续子序列

60 阅读1分钟
#include <iostream>
using namespace std;
const int N = 100010;
int main(){
    int n;
    cin >> n;
    int a[N],s[N];
    for(int i = 0;i < n;i++) cin >> a[i];
    int res = 0;
    for(int i = 0,j = 0;i < n;i++){
        s[a[i]]++;
        while(s[a[i]] > 1){
//      重新找新的j
            s[a[j]]--;
            j++;
        }
        res = max(res, i - j + 1);
    }
    cout << res;
}