Last active
February 22, 2019 00:45
-
-
Save seve/4ab7b739a2ed95d3857f53fab524273f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyTrie(dict): | |
def __init__(self, word_list=None): | |
super(MyTrie, self).__init__() | |
self.id = 0 | |
# the charcter, a unique id, end charcter in a word | |
self.root = ('', self.id, False) | |
self[self.root] = [] | |
self.id += 1 | |
if word_list is not None: | |
for word in word_list: | |
self.add_word(word) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment