from typing importList, Tuple, Dict classSolution: deffindLongestWord(self, s: str, dictionary: List[str]) -> str: m = len(s) f = [[0] * 26for _ inrange(m)] f.append([m] * 26) print([chr(ord('a')+i) for i inrange(26)]) for i inrange(m - 1, -1, -1): print('[', end='') for j inrange(26): iford(s[i]) == j + 97: f[i][j] = i else: f[i][j] = f[i + 1][j] print("'{}', ".format(f[i][j]), end='') print() res = "" for t in dictionary: match = True j = 0 for i inrange(len(t)): if f[j][ord(t[i]) - 97] == m: match = False break j = f[j][ord(t[i]) - 97] + 1 ifmatch: iflen(t) > len(res) or (len(t) == len(res) and t < res): res = t return res