[题目链接(https://leetcode.com/problems/maximum-product-of-word-lengths/)
n方复杂度。感觉复杂度还是有点高。不知道有没有更好的方法。
public class Solution {
public int maxProduct(String[] words) {
int mask[]=new int [words.length];
for(int i=0;i<words.length;i++)
{
for(int j=0;j<words[i].length();j++)
{
mask[i]|=1<<(words[i].charAt(j)-'a');
}
}
int total=0;
for(int i=0;i<words.length;i++)
{
for(int j=i;j<words.length;j++)
{
if((mask[i]&mask[j])==0)
{
total=Math.max(total, words[i].length()*words[j].length());
}
}
}
return total;
}
}