#include using namespace std; class Solution { public: vector findSubstring(string s, vector &words) { vector res; if (s.empty() || words.empty()) { return res; } unordered_map ht; for (const auto &w : words) { ht[w]++; } int len = words[0].length(); for (int i = 0, j = 0; i < s.length() - words.size() * len + 1; i++) { unordered_map counting; for (j = 0; j < words.size(); j++) { string word = s.substr(i + j * len, len); if (++counting[word] > ht[word]) { break; } } if (j == words.size()) { res.push_back(i); } } return res; } };