leetcode 208.实现Trie
题目描述
字典树模板
class Trie:
def __init__(self):
"""
Initialize your data structure here.
"""
self.trie = {}
def insert(self, word: str) -> None:
"""
Inserts a word into the trie.
"""
curr = self.trie # 用一个指针进行字典的嵌套
for w in word:
if w not in curr:
curr[w] = {}
curr = curr[w]
curr["#"] = '#' # 使用#判断单词的结尾
def search(self, word: str) -> bool:
"""
Returns if the word is in the trie.
"""
curr = self.tri