MCPcopy Create free account
hub / github.com/ByteByteGoHq/coding-interview-patterns / search

Method search

kotlin/Tries/DesignATrie.kt:24–36  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected