leetcode 318. Maximum Product of Word Lengths

来源:互联网 发布:算法心得 编辑:程序博客网 时间:2024/06/07 22:05
class Solution(object):    def maxProduct(self, words):        """        :type words: List[str]        :rtype: int        """        bit_len_dict = dict()        for word in words:            mask = 0            for c in word:                mask |= (1<<(ord(c)-97))            bit_len_dict[mask] = max(len(word),bit_len_dict.get(mask,0))        res = 0            for i in bit_len_dict:            for j in bit_len_dict:                if i&j == 0 and bit_len_dict[i]*bit_len_dict[j] > res:                    res = bit_len_dict[i]*bit_len_dict[j]        return res
阅读全文
0 0
原创粉丝点击