| 7 | val root = TrieNode() |
| 8 | |
| 9 | fun insert(word: String) { |
| 10 | var node = root |
| 11 | for (c in word.toCharArray()) { |
| 12 | // For each character in the word, if it's not a child of |
| 13 | // the current node, create a new TrieNode for that |
| 14 | // character. |
| 15 | if (c !in node.children) { |
| 16 | node.children[c] = TrieNode() |
| 17 | } |
| 18 | node = node.children[c]!! |
| 19 | } |
| 20 | // Mark the last node as the end of a word. |
| 21 | node.isWord = true |
| 22 | } |
| 23 | |
| 24 | fun search(word: String): Boolean { |
| 25 | var node = root |
no test coverage detected