Straight Forward Python Solution


  • 1
    B
    class Solution(object):
        def maxProduct(self, words):
            lengths = [len(x) for x in words]
            bits = []
            for i in range(len(words)):
                result = 0
                bits.append(reduce(lambda x,y:x|1<<(ord(y)-ord('a')),[j for j in words[i]], 0))
            final = 0
            for i in range(len(lengths)):
                for j in range(i+1, len(lengths)):
                    if (bits[i]&bits[j] == 0 and lengths[i]*lengths[j] > final):
                        final = lengths[i]*lengths[j]
            return final

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.