You are viewing a single comment's thread. Return to all comments →
My solution is quite similar as yours, but why do I get 'runtime error' for several testcases?
class TrieNode: def __init__(self,value): self.data = value self.count = 0 self.children = {} class Trie: def __init__(self): self.root = TrieNode('') def add(self,keys): current = self.root for key in keys: if not key in current.children: node = TrieNode(key) node.count = 1 current.children[key] = node current = current.children[key] else: current = current.children[key] current.count += 1 def find(self,keys): current = self.root for key in keys: if not key in current.children: return 0 else: current = current.children[key] return current.count
Seems like cookies are disabled on this browser, please enable them to open this website
Tries: Contacts
You are viewing a single comment's thread. Return to all comments →
My solution is quite similar as yours, but why do I get 'runtime error' for several testcases?