1. vector<int> findAnagrams(string s, string t) {
    2. unordered_map<char, int> needs;
    3. unordered_map<char, int> window;
    4. for(char c : t){
    5. ++needs[c];
    6. }
    7. int match = 0, start = 0, left = 0, right = 0, len = s.length(), minLen = INT_MAX;
    8. vector<int> res;
    9. while(right < len){
    10. char c1 = s[right];
    11. if(needs.count(c1)){
    12. ++window[c1];
    13. if(window[c1] == needs[c1]){
    14. ++match;
    15. }
    16. }
    17. ++right;
    18. while(match == needs.size()){
    19. if(right - left == t.size()){
    20. res.push_back(left);
    21. }
    22. char c2 = s[left];
    23. if(needs.count(c2)){
    24. --window[c2];
    25. if(window[c2] < needs[c2]){
    26. --match;
    27. }
    28. }
    29. ++left;
    30. }
    31. }
    32. return res;
    33. }