🔗 leetcode.com/problems/st…
题目
思路
- KMP,或者直接暴力,题目的数据量不大,为了简单写了暴力版本
代码
class Solution {
public:
bool is_substring(string sub, string st) {
if (sub.size() > st.size()) return false
for (int i = 0
int count = 0
for (int j = 0
if (sub[j] == st[i + j]) count++
else break
}
if (count == sub.size()) return true
}
return false
}
vector<string> stringMatching(vector<string>& words) {
vector<string> ans
for (int i = 0
for (int j = 0
if (i == j) continue
if (is_substring(words[i], words[j])) {
ans.push_back(words[i])
break
}
}
}
return ans
}
}