Clear Python code


  • 0
    J
    class Solution(object):
    def maxProduct(self, words):
        """
        :type words: List[str]
        :rtype: int
        """
        faker,res=[0]*len(words),0
        for i in xrange(len(faker)):
            faker[i]=reduce(lambda x,y:x|y,[1<<(ord(w)-97) for w in words[i]],0)#use bit to distinct diff char
        for i in xrange(len(faker)-1):
            for j in xrange(i+1,len(faker)):
                if faker[i]&faker[j]==0:
                    res=max(res,len(words[i])*len(words[j]))
        return res

Log in to reply
 

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