暴力求解没超时,那就这样吧
class Solution:def maxProduct(self, words: List[str]) -> int:ans = 0for i in range(len(words)):for j in range(i + 1, len(words)):if len(words[i]) * len(words[j]) < ans:continuet = 0for k in range(26):ch = chr(k + ord('a'))if ch in words[i] and ch in words[j]:t = 1breakif t == 0:ans = len(words[i]) * len(words[j])return ans