0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 21:28:48 +00:00

799. 最长连续不重复子序列

https://www.acwing.com/problem/content/submission/code_detail/10688919/
This commit is contained in:
Baoshuo Ren 2022-02-08 10:41:58 +08:00
parent 1aed9faffb
commit 7ce65aead5
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

21
AcWing/799/799.cpp Normal file
View File

@ -0,0 +1,21 @@
#include <iostream>
using std::cin;
using std::cout;
#define endl '\n'
int n, a[100005], s[100005], ans;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1, j = 1; i <= n; i++) {
s[a[i]]++;
while (s[a[i]] > 1) s[a[j++]]--;
ans = std::max(ans, i - j + 1);
}
cout << ans << endl;
return 0;
}