(self, word: str)
| 9 | self.root = TrieNode() |
| 10 | |
| 11 | def insert(self, word: str) -> None: |
| 12 | node = self.root |
| 13 | for c in word: |
| 14 | # For each character in the word, if it's not a child of |
| 15 | # the current node, create a new TrieNode for that |
| 16 | # character. |
| 17 | if c not in node.children: |
| 18 | node.children[c] = TrieNode() |
| 19 | node = node.children[c] |
| 20 | # Mark the last node as the end of a word. |
| 21 | node.is_word = True |
| 22 | |
| 23 | def search(self, word: str) -> bool: |
| 24 | node = self.root |