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

Method insert

cpp/Tries/design_a_trie.cpp:26–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24 }
25
26 void insert(std::string word) {
27 TrieNode* node = root;
28 for (char c : word) {
29 // For each character in the word, if it's not a child of
30 // the current node, create a new TrieNode for that
31 // character.
32 if (node->children.find(c) == node->children.end()) {
33 node->children[c] = new TrieNode();
34 }
35 node = node->children[c];
36 }
37 // Mark the last node as the end of a word.
38 node->isWord = true;
39 }
40
41 bool search(std::string word) {
42 TrieNode* node = root;

Callers 11

zeroStripingHashSetsFunction · 0.45
verifySudokuBoardFunction · 0.45
tripletSumBruteForceFunction · 0.45
exploreLevelFunction · 0.45
backtrackFunction · 0.45
dfsFunction · 0.45
inorderFunction · 0.45
linkedListLoopNaiveFunction · 0.45

Calls 1

findMethod · 0.45

Tested by 3

exploreLevelFunction · 0.36