def__init__(self): """ Initialize your data structure here. """ self.dic = {}
definsert(self, word: str) -> None: """ Inserts a word into the trie. """ temp = self.dic for one in word: if one notin temp: temp[one] = {} temp = temp[one] temp['end'] = True
defsearch(self, word: str) -> bool: """ Returns if the word is in the trie. """ temp = self.dic for one in word: if one notin temp: returnFalse temp = temp[one] return'end'in temp
defstartsWith(self, prefix: str) -> bool: """ Returns if there is any word in the trie that starts with the given prefix. """ temp = self.dic for one in prefix: if one notin temp: returnFalse temp = temp[one] returnTrue