本文主要是介绍每日一题 318. 最大单词长度乘积(中等),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
暴力求解没超时,那就这样吧
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
这篇关于每日一题 318. 最大单词长度乘积(中等)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!