Python解LeetCode 318: Maximum Product of Word Lengths

提供两种解法,第一种利用Python内置的set类型判断两个单词是否有重叠字符,复杂度高,无法通过全部测试;第二种方法使用位运算判断两个单词是否存在重叠字符,复杂度有所降低,可通过全部测试,但是运行时间排名也比较靠后。下述两种答案仅供参考交流,仍有很大的改进空间。

第一种解法:

from itertools import permutations

class Solution(object):
	def maxProduct(self, words):
	"""
	:type words: List[str]
	:rtype: int
	"""
	result = 0
	words = sorted(words, key=lambda item: len(item), reverse=

你可能感兴趣的:(python,算法与数据结构,python两两组合操作,python位操作,LeetCode,318题解)