| 39 | } |
| 40 | |
| 41 | bool search(std::string word) { |
| 42 | TrieNode* node = root; |
| 43 | for (char c : word) { |
| 44 | // For each character in the word, if it's not a child of |
| 45 | // the current node, the word doesn't exist in the Trie. |
| 46 | if (node->children.find(c) == node->children.end()) { |
| 47 | return false; |
| 48 | } |
| 49 | node = node->children[c]; |
| 50 | } |
| 51 | // Return whether the current node is marked as the end of the |
| 52 | // word. |
| 53 | return node->isWord; |
| 54 | } |
| 55 | |
| 56 | bool hasPrefix(std::string prefix) { |
| 57 | TrieNode* node = root; |