很简单的一道尺取法题目,首先用双指针寻找到满足要求的字串(包含26个小写字母),在通过右移左指针l来寻找到不符合条件的位置,再将答案进行记录就行了。
```#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+50;
string str;
map <char,int> m;
bool check(){
for(auto it : m){
if(it.second <= 0)
return false;
}
return true;
}
int main()
{
ios::sync_with_stdio(false);
cin >> str;
int l = 0,ans = 0x3f3f3f3f;
for(int i = 0; i < str.size(); i++){
m[str[i]]++;
while(m.size() == 26 && check()){
m[str[l++]]--;
if(ans > i - l + 1){
ans = i - l + 1;
}
}
}
cout << ans + 1 << endl;
return 0;