public class Solution {
public int maxProduct(String[] words) {
int max = 0 ;
int[] masks = new int[words.length];
for (int i = 0; i < masks.length; i++) {
for (char c : words[i].toCharArray()) {
masks[i] = (masks[i])|(1<<((int)(c-'a')));
}
}
System.out.println(Arrays.toString(masks));
for (int i = 0; i < masks.length; i++) {
for (int j = i+1; j < masks.length; j++) {
if (((masks[i]&masks[j])==0)&&(words[i].length()*words[j].length()>max)) {
max = words[i].length()*words[j].length();
}
}
}
return max;
}
}
318. Maximum Product of Word Lengths
最新推荐文章于 2024-08-18 09:01:18 发布