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

Method hasPrefix

cpp/Tries/design_a_trie.cpp:56–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54 }
55
56 bool hasPrefix(std::string prefix) {
57 TrieNode* node = root;
58 for (char c : prefix) {
59 if (node->children.find(c) == node->children.end()) {
60 return false;
61 }
62 node = node->children[c];
63 }
64 // Once we've traversed the nodes corresponding to each
65 // character in the prefix, return True.
66 return true;
67 }
68
69private:
70 TrieNode* root;

Callers

nothing calls this directly

Calls 1

findMethod · 0.45

Tested by

no test coverage detected