1、尺取
2、比较
class Solution { public: vector<int> findAnagrams(string s, string p) { int len2=p.size(); int len1=s.size(); int i,j; int a[30]; int b[30]; vector <int >vec; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); for(j=0;j<len2;j++){ a[p[j]-'a']++; } int sum=0; int k=0; for(j=0;j<=len1-1;j++){ b[s[j]-'a']++; sum++; if(sum==len2) { for(i=0;i<=25;i++) if(b[i]!=a[i]) break; if(i==26) { vec.push_back(k); b[s[k]-'a']--; k++; sum--; } else { b[s[k]-'a']--; k++; sum--; } } } return vec; } };
标签:30,string,int,异位,memset,力扣,438,sizeof,size From: https://www.cnblogs.com/bhd123/p/17239516.html