799. 最长连续不重复子序列 【双指针经典板子题】
生活随笔
收集整理的這篇文章主要介紹了
799. 最长连续不重复子序列 【双指针经典板子题】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
https://www.acwing.com/problem/content/description/801/
自己寫的笨方法:
#include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int N=1e5+10; int a[N]; bool hush[100005]; int ans; int main(void) {int n;cin>>n;for(int i=0;i<n;i++) scanf("%d",&a[i]);for(int i=0,j=0;i<n;i++){j=i;int k=0;memset(hush,0,sizeof hush);while(j<n&&!hush[a[j]]) k++,hush[a[j]]=true,j++;ans=max(ans,k);}cout<<ans<<endl;return 0; }y神的思路:
總結
以上是生活随笔為你收集整理的799. 最长连续不重复子序列 【双指针经典板子题】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 801. 二进制中1的个数 【二进制的
- 下一篇: 第一章 基础算法 【完结】