leetcode 438. 找到字符串中所有字母异位词
作者:互联网
class Solution {
public:
vector<int> findAnagrams(string s, string p) {
vector<int> SV(26, 0);
vector<int> PV(26, 0);
vector<int> ans;
for(auto ch : p) PV[ch - 'a']++;
for(int ii = 0; ii < s.size(); ii++) {
SV[s[ii] - 'a']++;
if(ii >= p.size() - 1) {
int jj = 0;
while(jj < 26 && SV[jj] >= PV[jj]) jj++;
if(jj == 26) ans.push_back(ii - p.size() + 1);
SV[s[ii - p.size() + 1] - 'a']--;
}
}
return ans;
}
};
标签:26,438,++,异位,SV,ii,jj,leetcode,size 来源: https://blog.csdn.net/m0_37454852/article/details/115419756