java.lang.Object
g0301_0400.s0318_maximum_product_of_word_lengths.Solution

public class Solution extends Object
318 - Maximum Product of Word Lengths.<p>Medium</p> <p>Given a string array <code>words</code>, return <em>the maximum value of</em> <code>length(word[i]) * length(word[j])</code> <em>where the two words do not share common letters</em>. If no such two words exist, return <code>0</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> words = [&ldquo;abcw&rdquo;,&ldquo;baz&rdquo;,&ldquo;foo&rdquo;,&ldquo;bar&rdquo;,&ldquo;xtfn&rdquo;,&ldquo;abcdef&rdquo;]</p> <p><strong>Output:</strong> 16</p> <p><strong>Explanation:</strong> The two words can be &ldquo;abcw&rdquo;, &ldquo;xtfn&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> words = [&ldquo;a&rdquo;,&ldquo;ab&rdquo;,&ldquo;abc&rdquo;,&ldquo;d&rdquo;,&ldquo;cd&rdquo;,&ldquo;bcd&rdquo;,&ldquo;abcd&rdquo;]</p> <p><strong>Output:</strong> 4</p> <p><strong>Explanation:</strong> The two words can be &ldquo;ab&rdquo;, &ldquo;cd&rdquo;.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> words = [&ldquo;a&rdquo;,&ldquo;aa&rdquo;,&ldquo;aaa&rdquo;,&ldquo;aaaa&rdquo;]</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> No such pair of words.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>2 <= words.length <= 1000</code></li> <li><code>1 <= words[i].length <= 1000</code></li> <li><code>words[i]</code> consists only of lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maxProduct

      public int maxProduct(String[] words)