class Solution {
public:
vector<int> findAnagrams(string s, string p) {
unordered_map<char,int> window,hash;
vector<int> res;
for(auto i:p) hash[i]++;
for(int i=0,j=0;i<s.size();i++)
{
window[s[i]]++;
if(i>=p.size())
{
window[s[j]]--;
if(window[s[j]]==0) window.erase(s[j]);
j++;
}
if(window==hash) res.push_back(j);
}
return res;
}
};
标签:hash,Leetcode438,++,异位,window,res,字符串,string
From: https://www.cnblogs.com/tangxibomb/p/17587288.html