//核心在于尺取,其中也有利用了桶的思想,
//我是单独写了一个函数来判断是否满足条件,使得整体的代码更清晰
//笱蒻一枚有问题请指正;
#include<iostream>
#include<string.h>
using namespace std;
#define N 1000006
char op[1000000];
int check(int o[]){//当整形数组中的所有都不为0,既所有的小写字母都存在的话返回值为1
for(int i=0;i<26;i++){
if(o[i]==0)return 0;//只有有一个个数为0,那么就不符合条件,返回0;
}
return 1;
}
int main(){
int b[27]={0};//开了一个大小27的整形的数组,其中a[0]的大小对应a的个数,以此类推;
cin>>op;
int f=strlen(op);
int l=0,r=0,hu,ans=N;
while(l<=f){
while(r<f&&check(b)!=1){
int e=op[r]-'a';//如果op[r]为a的话,那么e就等于a-'a'既0;
b[e]++;
r++;
}
if(check(b)==1)hu=r-l;
ans=min(hu,ans);
l++;
b[op[l-1]-'a']--; //l右移,所以l本身的那个字符要减去一个
}
if(ans==N)cout<<0<<endl;//ans==N代表一直都没凑齐26个小写字符; 所以输出0;反之则输出答案;
else cout<<ans<<endl;
return 0;
}</iostream>