程序员面试金典——18.8子串判断
Solution1:我的答案
利用了C++ STL中自带的find函数,有点投机取巧的意思,正统方法是用trie树(单词查找树)来做,那就麻烦了许多
class Substr {
public:
vector<bool> chkSubStr(vector<string> p, int n, string s) {
// write code here
vector<bool> res;
if (n <= 0 || s == "")
return res;
else {
for (int i = 0; i < n; i++) {
if(s.find(p[i]) == string::npos)
res.push_back(false);
else
res.push_back(true);
}
return res;
}
}
};
Solution2:利用单词查找树,trie树来做