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

Method search

cpp/Tries/design_a_trie.cpp:41–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39 }
40
41 bool search(std::string word) {
42 TrieNode* node = root;
43 for (char c : word) {
44 // For each character in the word, if it's not a child of
45 // the current node, the word doesn't exist in the Trie.
46 if (node->children.find(c) == node->children.end()) {
47 return false;
48 }
49 node = node->children[c];
50 }
51 // Return whether the current node is marked as the end of the
52 // word.
53 return node->isWord;
54 }
55
56 bool hasPrefix(std::string prefix) {
57 TrieNode* node = root;

Callers

nothing calls this directly

Calls 1

findMethod · 0.45

Tested by

no test coverage detected