(String word)
| 18 | } |
| 19 | |
| 20 | public void insert(String word) { |
| 21 | TrieNode node = this.root; |
| 22 | for (char c : word.toCharArray()) { |
| 23 | // For each character in the word, if it's not a child of |
| 24 | // the current node, create a new TrieNode for that |
| 25 | // character. |
| 26 | node.children.putIfAbsent(c, new TrieNode()); |
| 27 | node = node.children.get(c); |
| 28 | } |
| 29 | // Mark the last node as the end of a word. |
| 30 | node.isWord = true; |
| 31 | } |
| 32 | |
| 33 | public boolean search(String word) { |
| 34 | TrieNode node = this.root; |