Skip to content

Instantly share code, notes, and snippets.

@shuuchen
Created May 27, 2019 08:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shuuchen/81f5ee20eeb20b26c3ada5a35fddb983 to your computer and use it in GitHub Desktop.
Save shuuchen/81f5ee20eeb20b26c3ada5a35fddb983 to your computer and use it in GitHub Desktop.
Implementation of trie
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