File tree Expand file tree Collapse file tree 1 file changed +4
-9
lines changed
Expand file tree Collapse file tree 1 file changed +4
-9
lines changed Original file line number Diff line number Diff line change 44 */
55var maxProduct = function ( words ) {
66 var max = 0 ;
7- var bitDict = [ ] ;
7+ var mask = [ ] ;
88 for ( var i = 0 ; i < words . length ; i ++ ) {
99 for ( var j = 0 ; j < words [ i ] . length ; j ++ ) {
10- bitDict [ i ] |= Math . pow ( 2 , words [ i ] [ j ] . charCodeAt ( ) - 'a' . charCodeAt ( ) ) ;
10+ mask [ i ] |= Math . pow ( 2 , words [ i ] [ j ] . charCodeAt ( ) - 'a' . charCodeAt ( ) ) ;
1111 }
1212 }
1313
1414 for ( i = 0 ; i < words . length ; i ++ ) {
15- for ( j = 0 ; j < words . length ; j ++ ) {
16- if ( i !== j && ! hasSharedLetter ( i , j ) ) {
15+ for ( j = 0 ; j < i ; j ++ ) {
16+ if ( ( mask [ i ] & mask [ j ] ) === 0 ) {
1717 max = Math . max ( max , words [ i ] . length * words [ j ] . length ) ;
1818 }
1919 }
2020 }
2121 return max ;
22-
23- function hasSharedLetter ( index1 , index2 ) {
24- if ( ( bitDict [ index1 ] & bitDict [ index2 ] ) === 0 ) return false ;
25- return true ;
26- }
2722} ;
You can’t perform that action at this time.
0 commit comments