# LEETCODE 318. Maximum Product of Word Lengths 解题思路分析

```输入: ["abcw","baz","foo","bar","xtfn","abcdef"]

```输入: `["a","ab","abc","d","cd","bcd","abcd"]`

```输入: `["a","aa","aaa","aaaa"]`

`int[][] count = new int[words.length][26];`

```public int maxProduct(String[] words) {
int[] bitmap = new int[words.length];
for(int i=0;i<words.length;i++){
char[] arr=words[i].toCharArray();
int bit=0;
for(int j=0;j<arr.length;j++){
bit |= (1<<(arr[j]-'a'));
}
bitmap[i]=bit;
}
int max=0;
for(int i=0;i<words.length;i++){
for(int j=i+1;j<words.length;j++){
if((bitmap[i]&bitmap[j])==0){
max=Math.max(max,words[i].length()*words[j].length());
}
}
}
return max;
}```

Runtime: 6 ms, faster than 99.77% of Java online submissions for Maximum Product of Word Lengths.

Memory Usage: 39.4 MB, less than 36.84% of Java online submissions for Maximum Product of Word Lengths.

```public int maxProduct(String[] words) {
int[][] count = new int[words.length][26];
for(int i=0;i<words.length;i++){
char[] arr=words[i].toCharArray();
for(int j=0;j<arr.length;j++){
count[i][arr[j]-'a']++;
}
}
int max=0;
for(int i=0;i<words.length;i++){
for(int j=i+1;j<words.length;j++){
boolean isValid=true;
for(int k=0;k<26;k++){
if(count[i][k]>0&&count[j][k]>0){
isValid=false;
break;
}
}
if(isValid) max=Math.max(max,words[i].length()*words[j].length());
}
}
return max;
}```

Runtime: 24 ms, faster than 42.32% of Java online submissions for Maximum Product of Word Lengths.

Memory Usage: 39.4 MB, less than 36.84% of Java online submissions for Maximum Product of Word Lengths.