Created
May 24, 2017 17:04
-
-
Save BiruLyu/c83637e12b919f4e1c1445f9d7585bca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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