MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / startsWith

Method startsWith

python/0208-implement-trie-prefix-tree.py:38–48  ·  view source on GitHub ↗

Returns if there is any word in the trie that starts with the given prefix.

(self, prefix: str)

Source from the content-addressed store, hash-verified

36 return curr.end
37
38 def startsWith(self, prefix: str) -> bool:
39 """
40 Returns if there is any word in the trie that starts with the given prefix.
41 """
42 curr = self.root
43 for c in prefix:
44 i = ord(c) - ord("a")
45 if curr.children[i] is None:
46 return False
47 curr = curr.children[i]
48 return True

Callers 2

updateSiteData.jsFile · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected