class Solution { // linter update 438 O(N) O(1)
public:
vector<int> findAnagrams(string s, string p) {
int n = s.size();
int m = p.size();
if (m > n) return {};
int cnt[26] = {};
int need = m;
for (char c : p) ++cnt[c - 'a'];
vector<int> ans;
for (int r = 0; r < n; ++r) {
if (cnt[s[r] - 'a']-- > 0) --need;
if (r >= m && cnt[s[r - m] - 'a']++ >= 0) ++need;
if (!need) ans.push_back(r - m + 1);
}
return ans;
}
};
感謝好心人們的幫助
https://google.github.io/styleguide/cppguide.html
https://www.weforum.org/impact/advanced-tecnologies-manufacturing-factories-scaling-innovations/