def findLastNode(self, string): ''' @param string: string to be searched @return: (index, node). index: int. first char(string[index]) of string not found in Trie tree. Otherwise, the length of string node: dict. node doesn't have string[index]. ''' node = self.root index = 0 while index < len(string): char = string[index] if char in node: node = node[char] else: break index += 1 return (index, node)
def printTree(self, node, layer): if len(node) == 0: return '\n'