原题链接:1408. 数组中的字符串匹配
solution:
class Solution {
public:
vector<string> stringMatching(vector<string>& words) {
vector<string> res; //定义返回值
sort(words.begin(), words.end(),[](const string &a, const string &b){
return a.size() == b.size() ? a < b : a.size() < b.size();
}); //排序
for(int i = 0;i < words.size();i++)
for(int j = i + 1;j < words.size();j++) {
if(words[j].find(words[i]) != -1) {
res.push_back(words[i]);
break;
}
}
return res;
}
};