12 lines Java solution. Bits 79%. Easy to understand.


  • 0
    O
    
        public int maxProduct(String[] words) {    	
        	int result = 0, i = 0;
        	int[] bitMask = new int[words.length];
        	for(String s: words) {
        		for(char ch: s.toCharArray()) 
        			bitMask[i] |= 1 << (ch - 97);
        		i++;
        	}
        	for(int j = 0; j < words.length; j++) 
        		for(i = j; i < words.length; i++) 
        			if ((bitMask[i] & bitMask[j]) == 0) 
        				result = Math.max(result, words[j].length()*words[i].length());
        	return result;
        }
    

Log in to reply
 

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