For this problem:
1. use i = start; i < start + total; i += each and s.substr(i, each)
2. or i = 0; i < len; i++ and s.substr(start + i*each, each);
1 class Solution { 2 public: 3 bool findExist(string s, int start, int each, int len, unordered_map<string, int> dict) { 4 for (int i = 0; i < len; i++) { 5 if (dict[s.substr(start + i*each, each)] > 0) dict[s.substr(start + i*each, each)]--; 6 else return false; 7 } 8 return true; 9 } 10 vector<int> findSubstring(string S, vector<string> &L) { 11 vector<int> result; 12 if (L.size() == 0) return result; 13 int len = L.size(), each = L[0].size(), total = each*len, i = 0; 14 unordered_map<string, int> dict; 15 for (string s : L) { 16 dict[s]++; 17 } 18 while (i + total <= S.size()) { 19 if (findExist(S, i, each, len, dict)) { 20 result.push_back(i); 21 } 22 i++; 23 } 24 return result; 25 } 26 };