没什么好说的,滑就是了……
class Solution {
public:
vector<int> findAnagrams(string s, string p) {
vector<int> res;
vector<int> dic(26),window(26);
for(char c:p)
++dic[c-'a'];
for(int pl=0,pr=0;pr<s.size();++pr)
{
++window[s[pr]-'a'];
while(pr+1>pl+p.size())
--window[s[pl++]-'a'];
if(window==dic)
res.push_back(pl);
}
return res;
}
};