题目:1408. 数组中的字符串匹配
思路:暴力枚举,枚举每两个字符串进行比对。时间复杂度0(n^2*L)
class Solution {
public:
vector<string> stringMatching(vector<string>& words) {
//集合,避免重复
set<string> st;
for(int i=0;i<words.size();i++){
for(int j=0;j<words.size();j++){
//两个字符不相等
if(words[i]!=words[j]){
//能在前一个字符当中出现
if(words[i].find(words[j])<words[i].size()) st.insert(words[j]);
}
}
}
vector<string> v;
for(auto x:st){
v.push_back(x);
}
return v;
}
};