题目:
题解:
class Trie:def __init__(self):self.children = [None] * 26self.isEnd = Falsedef searchPrefix(self, prefix: str) -> "Trie":node = selffor ch in prefix:ch = ord(ch) - ord("a")if not node.children[ch]:return Nonenode = node.children[ch]return nodedef insert(self, word: str) -> None:node = selffor ch in word:ch = ord(ch) - ord("a")if not node.children[ch]:node.children[ch] = Trie()node = node.children[ch]node.isEnd = Truedef search(self, word: str) -> bool:node = self.searchPrefix(word)return node is not None and node.isEnddef startsWith(self, prefix: str) -> bool:return self.searchPrefix(prefix) is not None