Share my first solution


  • 0
    M

    This is my first post in leetcode . Share my solution and learn from you。
    、、、
    class Solution {
    public:
    vector<int> findAnagrams(string s, string p) {
    vector<int> vs(26,0), vp(26,0);
    for(int i=0;i<p.size();i++){
    vp[ p[i]-'a' ]++;
    }
    vector<int> index;
    int sz=p.size();
    for(int i=0;i<s.size();i++){
    vs[s[i]-'a']++;
    if(i>=sz){
    vs[s[i-sz]-'a']--;
    }
    if(vs==vp){
    index.push_back(i-sz+1);
    }
    }
    return index;

    }
    

    };
    、、、


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.