标签:
1 public class Solution { 2 public int maxProduct(String[] words) { 3 if (words.length < 2) { 4 return 0; 5 } 6 7 int[] bitMap = new int[words.length]; 8 for (int i = 0; i < words.length; i++) { 9 for (char c : words[i].toCharArray()) { 10 bitMap[i] |= 1 << (int)(c - ‘a‘); 11 } 12 } 13 14 int result = 0; 15 for (int i = 0; i < words.length; i++) { 16 for (int j = i + 1; j < words.length; j++) { 17 if ((bitMap[i] & bitMap[j]) == 0) { 18 result = Math.max(result, words[i].length() * words[j].length()); 19 } 20 } 21 } 22 return result; 23 } 24 }
1. Do not forget to left shift the number.
Maximum Product of word lengths
标签:
原文地址:http://www.cnblogs.com/shuashuashua/p/5642230.html