#include<iostream>usingnamespace std;constint N =100010;int arr[N], temp[N];intmain(){int n, res =0;
cin >> n;for(int i =0; i < n; i ++) cin >> arr[i];for(int i =0, j =0; i < n; i ++){
temp[arr[i]]++;while(j <= i && temp[arr[i]]>1){// 剔出重复元素之前的数据
temp[arr[j]]--;
j ++;}
res =max(res, i - j +1);}
cout << res << endl;return0;}
#include<iostream>usingnamespace std;constint N =100010;int a[N], b[N];intmain(){int n, m;
cin >> n >> m;for(int i =0; i < n; i ++) cin >> a[i];for(int i =0; i < m; i ++) cin >> b[i];int i =0, j =0;while(i < n && j < m){if(a[i]== b[j]) i ++;
j ++;}if(i >= n){ cout <<"Yes"<< endl;}else{ cout <<"No"<< endl;}return0;}
相关题目最长不含重复字符的子串#include <iostream>using namespace std;const int N = 100010;int arr[N], temp[N];int main() { int n, res = 0; cin >> n; for (int i = 0; i < n; i ++) cin >> arr[i]; for (int i = 0, j = 0; i