def__init__(self): """ Initialize your data structure here. """
defaddWord(self, word: str) -> None: """ Adds a word into the data structure. """
defsearch(self, word: str) -> bool: """ Returns if the word is in the data structure. A word could contain the dot character '.' to represent any one letter. """
# Your WordDictionary object will be instantiated and called as such: # obj = WordDictionary() # obj.addWord(word) # param_2 = obj.search(word)
import collections as cl classNode: def__init__(self): self.Children=cl.defaultdict(Node) self.isWord=False
classWordDictionary:
def__init__(self): self.root=Node() """ Initialize your data structure here. """
defaddWord(self, word: str) -> None: node = self.root for i in word: node =node.Children[i] node.isWord=True#对单词结尾标记 """ Adds a word into the data structure. """