Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. class Solution {
  2. public:
  3. vector<int> findAnagrams(string s, string p) {
  4. if (s.empty()) return {};
  5. vector<int> res, cnt(128, 0);
  6. int ns = s.size(), np = p.size(), i = 0;
  7. for (char c : p) ++cnt[c];
  8. while (i < ns) {
  9. bool success = true;
  10. vector<int> tmp = cnt;
  11. for(int j = i; j < i + np; j++) {
  12. //cout << j << " to " << i + np << "<> " << s[j] << " : " << tmp[s[j]] << endl;
  13. if (--tmp[s[j]] < 0) {
  14. success = false;
  15. break;
  16. }
  17. }
  18. if (success) res.push_back(i);
  19. i++;
  20. }
  21. return res;
  22. }
  23. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement