| 22 | } |
| 23 | |
| 24 | fun search(word: String): Boolean { |
| 25 | var node = root |
| 26 | for (c in word.toCharArray()) { |
| 27 | // For each character in the word, if it's not a child of |
| 28 | // the current node, the word doesn't exist in the Trie. |
| 29 | if (c !in node.children) { |
| 30 | return false |
| 31 | } |
| 32 | node = node.children[c]!! |
| 33 | } |
| 34 | // Return whether the current node is marked as the end of the word. |
| 35 | return node.isWord |
| 36 | } |
| 37 | |
| 38 | fun hasPrefix(prefix: String): Boolean { |
| 39 | var node = root |
nothing calls this directly
no outgoing calls
no test coverage detected