You is given a string, s, and a list of words, words, that is all of the same length. Find all starting indices of substring (s) in S, a concatenation of each word in wordsexactly once and without any I ntervening characters.
Shame!!!
English is not good, this question to see half a day to understand the meaning of the topic: In the string s to find some substrings, the sub-string of the subscript index returned to the array to save.
So what are the conditions for a substring to be fulfilled? Substrings are filled with all the words in the array words, and all words appear only once.
Note that all eligible substrings are found!!!!!
It should not be difficult to understand the problem after reading it. Note-----Array of words words should probably be duplicated.
1 classSolution {2 Public:3vector<int> findsubstring (stringS, vector<string>&words) {4vector<int>Res;5map<string,int>All ;6map<string,int>cur;7 intnums=words.size ();8 for(ints=0; s<nums;s++)9all[words[s]]++;Ten intlen=words[0].size (); One if(S.size () <len*nums)returnRes; A for(intI=0; I<=s.size ()-len*nums;i++) - { - cur.clear (); the intJ; - for(j=0; j<nums;j++) - { - stringSubs=s.substr (i+j*Len,len); + if(All.find (Subs) ==all.end ()) Break; -cur[subs]++; + if(Cur[subs]>all[subs]) Break; A } at if(j==nums) Res.push_back (i); - } - returnRes; - } -};
Ubstring with concatenation of all Words