LeeCode(30)

class Solution {
public:
    vector<int> findSubstring(string s, vector<string>& words) {
        vector<int>v;
        string t;
        int n = s.size(),n2 = words.size(),n3 = words[0].size(),len;
        unordered_map<string,int>mp,tmp;
        if(n<n2*n3){
            return {};
        }
        for(auto str:words){
            ++mp[str];
        }
        for(int i=0;i+n2*n3<=n;i++){
            int j;
            for(j=i;j<i+n2*n3;j+=n3){
                t = s.substr(j,n3);
                if(mp.find(t)==mp.end())break;
                ++tmp[t];
            }
            if(j==i+n2*n3&&tmp==mp)v.push_back(i);
            tmp.clear();
        }
        return v;
    }
};

 

上一篇:30.数值的扩展


下一篇:Redis为什么快