not worth it, no prunning still 31ms


  • 0
    I
    public class Solution {
        public int maxProduct(String[] words) {
            int ans = 0, n = words.length;
            int[] bitmaps = new int[n];
            for (int i = 0; i < n; i++) {
                for (char c : words[i].toCharArray()) {
                    bitmaps[i] |= 1 << c - 'a';
                }
                for (int j = 0, len = words[i].length(); j < i; j++) {
                    if ((bitmaps[j] & bitmaps[i]) == 0)
                        ans = Math.max(ans, words[j].length() * len);
                }
            }
            return ans;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.