Posted on

Description

Submission

class Solution {
public:
    int maxProduct(vector<string>& words) {
        int n = words.size();
        vector<int> wordVals(n);

        for(int i = 0; i < n; ++i) {
            auto& word = words[i];
            int cur = 0;
            for(char ch: word) {
                if(!((1<<(ch-'a'))&cur)) cur += (1<<(ch-'a'));
            }
            wordVals[i] = cur;
        }

        int ret = 0;
        for(int i = 0; i < n; ++i) {
            for(int j = i + 1; j < n; ++j) {
                if(!(wordVals[i] & wordVals[j])) {
                    ret = max(int(words[i].length() * words[j].length()), ret);
                }
            }
        }
        
        return ret;
    }
};

Leave a Reply

Your email address will not be published. Required fields are marked *