CF 701C

题目:

滑动队列

题解:

水题秒做系列。。

#include<iostream>
#include<string>
#include<map>
using namespace std;

string str;
map<char,int> mmm;

int main(){
    int len;
    int cnt=0;
    cin>>len>>str;
    for(int i=0;i<len;i++){
        if(mmm[str[i]]==0){
            mmm[str[i]]++;
            cnt++;
        }
    }
    mmm.clear();
    int from=0;
    int to=0;
    int ans=1e9+1;
    int now=0;
    while(to<len){
        while(now<cnt){
            mmm[str[to]]++;
            if(mmm[str[to]]==1){
                now++;
            }
            to++;
            if(to>=len) break;
        }
        while(now==cnt){
            mmm[str[from]]--;
            if(mmm[str[from]]==0){
                ans=min(ans,to-from);
                now--;
            }
            from++;
        }
    }
    cout<<ans<<endl;
}

猜你喜欢

转载自blog.csdn.net/mengwuyaaa/article/details/80199547