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

Method insert

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

Source from the content-addressed store, hash-verified

9 self.root = TrieNode()
10
11 def insert(self, word: str) -> None:
12 node = self.root
13 for c in word:
14 # For each character in the word, if it's not a child of
15 # the current node, create a new TrieNode for that
16 # character.
17 if c not in node.children:
18 node.children[c] = TrieNode()
19 node = node.children[c]
20 # Mark the last node as the end of a word.
21 node.is_word = True
22
23 def search(self, word: str) -> bool:
24 node = self.root

Callers

nothing calls this directly

Calls 1

TrieNodeClass · 0.70

Tested by

no test coverage detected