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

Method hasPrefix

kotlin/Tries/DesignATrie.kt:38–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36 }
37
38 fun hasPrefix(prefix: String): Boolean {
39 var node = root
40 for (c in prefix.toCharArray()) {
41 if (c !in node.children) {
42 return false
43 }
44 node = node.children[c]!!
45 }
46 // Once we've traversed the nodes corresponding to each
47 // character in the prefix, return True.
48 return true
49 }
50}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected