双指针
for(int i = 0, j = 0; i < n; i ++){ while(j <= i && check(i, j)) j ++; //具体逻辑}
#include <iostream>#include <algorithm>#include <set>using namespace std;const int N = 1010;int n;int a[N];bool check(int l, int r){ set<int>s; for(int i = l; i <= r; i ++) s.insert(a[i]); if(s.size() != r - l + 1) return true; return false;}int main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for(int i = 0; i < n; i ++) cin >> a[i]; int ans = -1; for(int i = 0, j = 0; i < n; i ++) { while(j <= i && check(j, i)) j ++; ans = max(ans, i - j + 1); } cout << ans;// cout << a[1] << " " << a[2] << endl;// cout << check(1, 2);}