Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save BiruLyu/c83637e12b919f4e1c1445f9d7585bca to your computer and use it in GitHub Desktop.

Select an option

Save BiruLyu/c83637e12b919f4e1c1445f9d7585bca to your computer and use it in GitHub Desktop.
public class Solution {
public int maxProduct(String[] words) {
int res = 0;
if(words == null || words.length == 0) return res;
int len = words.length;
int[] vectors = new int[len];
for(int i = 0; i < len; i++){
String temp = words[i];
for(int j = 0; j < temp.length(); j++){
vectors[i] |= 1 << (temp.charAt(j) - 'a');
}
}
for(int i = 0; i < len; i++){
for(int j = i + 1; j < len; j++){
if(( vectors[i] & vectors[j] ) == 0){
res = Math.max(res, words[i].length() * words[j].length());
}
}
}
return res;
}
}
/*
["abcw","baz","foo","bar","xtfn","abcdef"]
["a", "ab", "abc", "d", "cd", "bcd", "abcd"]
["a", "aa", "aaa", "aaaa"]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment