Skip to content

Latest commit

 

History

History
30 lines (20 loc) · 547 Bytes

318.md

File metadata and controls

30 lines (20 loc) · 547 Bytes

318 Maximum Product of Word Lengths

Description

link


Solution

  • See Code

Code

O(n)

class Solution:
    def maxProduct(self, words: 'List[str]') -> 'int':
        d = {}
        for word in words:
            mask = 0
            for c in set(word):
                mask |= (1 << (ord(c) - 96))
            d[mask] = max(len(word), d.get(mask, 0))
        
        return max([d[x] * d[y] for x in d for y in d if not x & y] or [0])