You are viewing a single comment's thread. Return to all comments →
class Node(): def __init__(self, char): self.char = char self.children = dict() self.end = False def noPrefix(words): trie = Node("") for i in range(len(words)): word = words[i] head = trie for i in range(len(word)): char = word[i] new_head = head.children.get(char) if new_head: if i == len(word) -1 or new_head.end: print("BAD SET") print(word) exit() head = new_head else: head.children[char] = Node(char) head = head.children[char] if i == len(word) -1: head.end = True print("GOOD SET")
Seems like cookies are disabled on this browser, please enable them to open this website
No Prefix Set
You are viewing a single comment's thread. Return to all comments →