Why this is so slow?


  • 0
    S

    class Solution {
    public:
    vector<int> findAnagrams(string s, string p) {

        vector<int> res;
        do
        {
            int offset = 0;
            while (s.find(p, offset) != string::npos) 
            {
                res.push_back(s.find(p,offset));
                offset = s.find(p,offset) + 1;
            }
            
        }while(next_permutation(p.begin(),p.end()));
        
        return res;
        
    }
    

    };


Log in to reply
 

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