经典尺取法
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
char str[MAXN];
int mark[26];
bool check()
{
int cnt = 0;
for(int i = 0; i < 26; ++i)
if(mark[i] > 0)
++cnt;
if(cnt == 26)
return true;
else
return false;
}
int main()
{
scanf("%s",str);
int len = strlen(str);
int s = 0,e = 0,nl = 0;
int res = MAXN;
while(e < len)
{
if(check())
{
if(nl < res)
res = nl;
--mark[str[s++]-'A'];
--nl;
}
else
{
++mark[str[e++]-'A'];
++nl;
}
}
if(res == MAXN)
printf("No Solution\n");
else
printf("%d\n",res);
return 0;
}