40
40
class Solution :
41
41
def maxProduct (self , words : List[str ]) -> int :
42
42
n = len (words)
43
- masks = [0 ] * n
43
+ mask = [0 ] * n
44
44
for i, word in enumerate (words):
45
- for c in word:
46
- masks [i] |= ( 1 << (ord (c ) - ord (' a' ) ))
45
+ for ch in word:
46
+ mask [i] |= 1 << (ord (ch ) - ord (' a' ))
47
47
ans = 0
48
48
for i in range (n - 1 ):
49
49
for j in range (i + 1 , n):
50
- if (masks [i] & masks [j]) == 0 :
50
+ if mask [i] & mask [j] == 0 :
51
51
ans = max (ans, len (words[i]) * len (words[j]))
52
52
return ans
53
53
```
@@ -86,14 +86,14 @@ class Solution {
86
86
public:
87
87
int maxProduct(vector<string >& words) {
88
88
int n = words.size();
89
- vector<int > masks (n);
89
+ vector<int > mask (n);
90
90
for (int i = 0; i < n; ++i)
91
- for (char c : words[ i] )
92
- masks [ i] |= ( 1 << (c - 'a') );
91
+ for (char ch : words[ i] )
92
+ mask [ i] |= 1 << (ch - 'a');
93
93
int ans = 0;
94
94
for (int i = 0; i < n - 1; ++i)
95
95
for (int j = i + 1; j < n; ++j)
96
- if ((masks [ i] & masks [ j] ) == 0 )
96
+ if (!(mask [ i] & mask [ j] ))
97
97
ans = max(ans, (int) (words[ i] .size() * words[ j] .size()));
98
98
return ans;
99
99
}
@@ -105,16 +105,16 @@ public:
105
105
```go
106
106
func maxProduct(words []string) int {
107
107
n := len(words)
108
- masks := make([]int, n)
108
+ mask := make([]int, n)
109
109
for i, word := range words {
110
110
for _, c := range word {
111
- masks [i] |= (1 << (c - 'a'))
111
+ mask [i] |= (1 << (c - 'a'))
112
112
}
113
113
}
114
114
ans := 0
115
115
for i := 0; i < n-1; i++ {
116
116
for j := i + 1; j < n; j++ {
117
- if (masks [i] & masks [j]) == 0 {
117
+ if mask [i]&mask [j] == 0 {
118
118
ans = max(ans, len(words[i])*len(words[j]))
119
119
}
120
120
}
0 commit comments