classSolution { private: int cnt1[30] = {0}, cnt2[30] = {0}; public: boolcheck(){ int flag = 1; for (int i = 0; i < 26; i++) { if (cnt1[i] != cnt2[i]) flag = 0; } return flag; }
boolcheckInclusion(string s1, string s2){ if (s1.size() > s2.size()) return0; int n = s1.size(), m = s2.size(); for (int i = 0; i < n; i++) cnt1[s1[i] - 'a']++, cnt2[s2[i] - 'a']++; if (check()) return1; for (int i = n; i < m; i++) { cnt2[s2[i - n] - 'a']--; cnt2[s2[i] - 'a']++; if (check()) return1; } return0; } };