1class TrieNode:23def __init__(self):4self.children = {}5self.endOfWord = False678class StreamChecker:910def __init__(self, words: List[str]):11self.root = TrieNode()12self.qCur = self.root13self.stream = collections.deque()14cur = self.root15for word in words:16for i in range(len(word) - 1, -1, -1):17ch = word[i]18if ch not in cur.children:19cur.children[ch] = TrieNode()20cur = cur.children[ch]21cur.endOfWord = True22cur = self.root2324def query(self, letter: str) -> bool:25self.stream.appendleft(letter)26cur = self.root27for ch in self.stream:28if ch not in cur.children:29return False30else:31cur = cur.children[ch]32if cur.endOfWord:33return True34return False