1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| #include <iostream> using namespace std;
const int N = 100010; int a[N], s[N];
int main() { int n; cin >> 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) { s[a[j]]--; j++; } res = max(res, i - j + 1); } cout << res; return 0; }
|