详细思路
class Solution { public: vector<int> findSubstring(string s, vector<string>& words) { vector<int>ans; unordered_map<string,int>need; int len=words[0].size(); int allLen=0; for(auto word:words){ need[word]++; allLen+=len; } for(int i=0;i+allLen<=s.size();i++){ unordered_map<string,int>have; bool ok=true; for(int j=i;j+len-i<=allLen;j+=len){ string temp=s.substr(j,len); if(need.find(temp)==need.end()){ ok=false; break; } have[temp]++; if(have[temp]>need[temp]){ ok=false; break; } if(j-i>allLen){ ok=false; break; } } if(ok)ans.push_back(i); } return ans; } };