[text] 暴力 最长

Viewer

copydownloadembedprintName: 暴力 最长
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int N = 100010;
  4. int a[N];
  5. int main(){
  6.     int n;
  7.     cin>>n;
  8.     for(int i = 0; i < n; i++) cin>>a[i];
  9.     int ans = 0;
  10.     for(int i = 0; i < n; i++){
  11.         unordered_map<int,bool> mp;
  12.         int j = i;
  13.         for( ; j < n&&!mp[a[j]]; j++) mp[a[j]] = true;
  14.         ans = max(ans,j-i);
  15.     }
  16.     cout<<ans;
  17.     return 0;
  18. }

Editor

You can edit this paste and save as new:


File Description
  • 暴力 最长
  • Paste Code
  • 01 Mar-2021
  • 394 Bytes
You can Share it: