首页 > 其他 > 详细

最长连续不重复序列

时间:2021-01-27 22:20:32      阅读:36      评论:0      收藏:0      [点我收藏+]

链接 : https://www.acwing.com/problem/content/801/

#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
inline int lowbit(int x) { return x & (-x); }
#define ll long long
#define pb push_back
#define PII pair<int, int>
#define fi first
#define se second
#define inf 0x3f3f3f3f
const int N = 1e5 + 7;
int a[N], cnt[N];
    
int main() {
    IO;
    int n, ans = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0, j = 0; i < n; ++i) {
        cnt[a[i]]++; 
        while (j < i && cnt[a[i]] >= 2) {
             cnt[a[j]]--;
             j++;
        }
        ans = max(ans, i - j + 1);
    }
    cout << ans << ‘\n‘; 
    return 0;
}

最长连续不重复序列

原文:https://www.cnblogs.com/phr2000/p/14336769.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!