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

Method search

python3/Tries/design_a_trie.py:23–33  ·  view source on GitHub ↗
(self, word: str)

Source from the content-addressed store, hash-verified

21 node.is_word = True
22
23 def search(self, word: str) -> bool:
24 node = self.root
25 for c in word:
26 # For each character in the word, if it's not a child of
27 # the current node, the word doesn't exist in the Trie.
28 if c not in node.children:
29 return False
30 node = node.children[c]
31 # Return whether the current node is marked as the end of the
32 # word.
33 return node.is_word
34
35 def has_prefix(self, prefix: str) -> bool:
36 node = self.root

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected