c++
class Solution {
public:
int maxProduct(vector<string>& words) {
if (words.empty()) return 0;
int len = words.size();
vector<int> mask(len, 0);
//binary mask
for (int i = 0; i < len; ++i) {
for (auto &s : words[i]) {
mask[i] |= 1<<(s - 'a');
}
}
int max_value = 0;
for (int i = 0; i < len; ++i) {
for (int j = i + 1; j < len; ++j) {
if ((mask[i] & mask[j]) == 0) {
if (words[i].size() * words[j].size() > max_value)
max_value = words[i].size() * words[j].size();
}
}
}
return max_value;
}
};
reference:
https://leetcode.com/discuss/82920/java-easy-version-to-understand