Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- bool checkInclusion(string s1, string s2) {
- int n = size(s1), m = size(s2);
- if (n > m) return false;
- vector<int> hash1(26, 0), hash2(26, 0);
- for (auto c : s1) hash1[c - 'a']++;
- int i = 0, j = 0;
- while (i < m) {
- hash2[s2[i] - 'a']++;
- if (i >= n) hash2[s2[j++] - 'a']--;
- if (hash1 == hash2) return true;
- i++;
- }
- return false;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement