Untitled
unknown
plain_text
a year ago
975 B
1
Indexable
Never
public static int maxProduct(String[] words) { if (words == null || words.length == 0) return 0; int len = words.length; int[] value = new int[len]; for (int i = 0; i < len; i++) { String tmp = words[i]; value[i] = 0; for (int j = 0; j < tmp.length(); j++) { value[i] |= 1 << (tmp.charAt(j) - 'a'); } } int maxProduct = 0; for (int i = 0; i < len; i++) for (int j = i + 1; j < len; j++) { if ((value[i] & value[j]) == 0 && (words[i].length() * words[j].length() > maxProduct)) maxProduct = words[i].length() * words[j].length(); } return maxProduct; } Given a string array words, return the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. If no such two words exist, return 0. Example 1: Input: words = ["abcw","baz","foo","bar","xtfn","abcdef"] Output: 16 Explanation: The two words can be "abcw", "xtfn". can you explain above code for above question