1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| class Solution { public int maxProduct(String[] words) { int ans = 0; Map<Integer, Integer> map = new HashMap<>(); for (String word : words) { int mask = 0, m = word.length(); for (int i = 0; i < m; ++i) { int u = word.charAt(i) - 'a'; mask |= (1 << u); } if (!map.containsKey(mask) || map.get(mask) < m) map.put(mask, m); } for (int a : map.keySet()) { for (int b : map.keySet()) { if (((a & b) == 0)) { ans = Math.max(ans, map.get(a) * map.get(b)); } } } return ans; } }
|