-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Open
Description
Bug Report for https://neetcode.io/problems/implement-prefix-tree
Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.
The test submission fails for the hashmap solution. Although the same test passes when copying the test use case.
Here is the code used:
class Node:
def __init__(self, children={}, is_end=False):
self.children = children
self.is_end = is_end
class PrefixTree:
def __init__(self):
self.root = Node()
def insert(self, word: str) -> None:
curr = self.root
for ch in word:
if ch not in curr.children:
curr.children[ch] = Node()
curr = curr.children[ch]
curr.is_end = True
def search(self, word: str) -> bool:
curr = self.root
for ch in word:
if ch not in curr.children:
return False
curr = curr.children[ch]
return curr.is_end
def startsWith(self, prefix: str) -> bool:
curr = self.root
for ch in prefix:
if ch not in curr.children:
return False
curr = curr.children[ch]
return TrueReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels