
Problem: 1408. String Matching in an Array 数组中的字符串匹配耗时100%按照长度排序的然后某个字符串从它后面开始找若它后面某个字符串包括了这个字符串就放入结果列表当中words[j].find(words[i]) ! string::nposCodeclass Solution { public: vectorstring stringMatching(vectorstring words) { int n words.size(); functionbool(string, string) func [](string a, string c) -bool { return a.size() c.size(); }; sort(words.begin(), words.end(), func); vectorstring ret; for(int i 0; i n; i) { for(int j i 1; j n; j) { if( words[j].find(words[i]) ! string::npos ) { ret.push_back(words[i]); break; } } } return ret; } };