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

Method has_prefix

python3/Tries/design_a_trie.py:35–43  ·  view source on GitHub ↗
(self, prefix: str)

Source from the content-addressed store, hash-verified

33 return node.is_word
34
35 def has_prefix(self, prefix: str) -> bool:
36 node = self.root
37 for c in prefix:
38 if c not in node.children:
39 return False
40 node = node.children[c]
41 # Once we've traversed the nodes corresponding to each
42 # character in the prefix, return True.
43 return True

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected