题意:找到一个包含所有小写字母的子串
题解:双指针
先找到一个从0开始包含所有小写字母的最短长度,并统计每个小写出现多少次,然后右指针移位,相应的字符统计++,然后对与左指针进行移位,移位到不能移位为止,即两指针中间出现有些字符不存在为止
#include<bits/stdc++.h> using namespace std; string s; int ansn=1e9,f[210]; int main(){ cin>>s; int l=0,r=-1,sum=0; while (1){ if (sum<26){ r++; if (r==s.length()) break; if (f[s[r]]==0) sum++;f[s[r]]++; }else{ if (f[s[l]]==1) sum--;f[s[l]]--; l++; } if (sum==26) ansn=min(ansn,r-l+1); } cout<<ansn<<endl; return 0; }