Created
May 27, 2019 08:34
-
-
Save shuuchen/81f5ee20eeb20b26c3ada5a35fddb983 to your computer and use it in GitHub Desktop.
Implementation of trie
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
from collections import defaultdict | |
class TrieNode: | |
def __init__(self): | |
self.isWord = False | |
self.children = defaultdict(TrieNode) | |
class Trie: | |
def __init__(self): | |
self.root = TrieNode() | |
def insert(self, word): | |
node = self.root | |
for c in word: | |
node = node.children[c] | |
node.isWord = True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment