修改Trie中的搜索判断函数,要求每一个前缀都出现即可
class Trie {
private:
vector<Trie*> children;
bool isEnd;
public:
Trie():children(26), isEnd(false) {}
void insert(string& word) {
Trie* node = this;
for (auto c : word) {
if (node->children[c - 'a'] == nullptr) {
node->children[c - 'a'] = new Trie();
}
node = node->children[c - 'a'];
}
node->isEnd = true;
}
bool search(string& word) {
Trie* node = this;
for (auto c : word) {
if (node->children[c - 'a'] == nullptr || !node->children[c-'a']->isEnd) {
return false;
}
node = node->children[c -