class Solution {
public:
vector<int> findAnagrams(string s, string p) {
std::vector<int> idxs;
std::string dstr = getHash(p);
for (int i = 0; i<s.length(); i++) {
std::string sub_str = s.substr(i, p.length());
auto hash_str = getHash(sub_str);
if (hash_str == dstr) {
idxs.push_back(i);
}
}
return idxs;
}
std::string getHash(std::string str) {
int count[26] = {0};
for (int i = 0; i<str.length(); i++) {
count[str[i]-'a']++;
}
std::ostringstream os;
for (int j = 0; j<26; j++) {
if (count[j] > 0)
os << char(j+'a') << count[j];
}
return os.str();
}
};