题目:
题解:
class Solution:def findLongestWord(self, s: str, dictionary: List[str]) -> str:m = len(s)f = [[0] * 26 for _ in range(m)]f.append([m] * 26)for i in range(m - 1, -1, -1):for j in range(26):if ord(s[i]) == j + 97:f[i][j] = ielse:f[i][j] = f[i + 1][j]res = ""for t in dictionary:match = Truej = 0for i in range(len(t)):if f[j][ord(t[i]) - 97] == m:match = Falsebreakj = f[j][ord(t[i]) - 97] + 1if match:if len(t) > len(res) or (len(t) == len(res) and t < res):res = treturn res