class Solution {
public:
vector<int> findSubstring(string s, vector<string>& words) {
vector<int> res;
int size = words.size();
if (size== 0 || s.empty() || size* words[0].length() > s.length()) {
return res;
}
map<string, int> m1;
for (int i = 0; i < size; i++) {
m1[words[i]]++;
}
for (int i = 0 ; i <= s.length() - size * words[0].length(); i++) {
map<string, int> m2;
bool flag = true;
for (int j = 0; j < size; j++) {
string tmp = s.substr(i + j * words[0].length(), words[0].length());
if (m1.find(tmp) != m1.end()) {
m2[tmp]++;
} else {
flag = false;
break;
}
if (m2[tmp] > m1[tmp]) {
flag = false;
break;
}
}
if (flag) {
res.push_back(i);
}
}
return res;
}
};