C++_Bit Manipulation_120ms_84.55%


  • 0
     class Solution {
     public:
     int maxProduct(vector<string>& words) {
        int res = 0;
        int k = words.size();
        vector<int> len(k, 0);
        for(int i = 0; i < k; i++){
            for(auto c : words[i]){
                len[i] |= (1 << (c-'a'));
        }
        
        for(int i = 0; i < k; i++){
            int a = words[i].size();
            for(int j = i+1; j < k; j++){
                if(!(len[i] & len[j])){
                    int b = words[j].size();
                    res = max(res, a*b);
                }
            }
        }
        return res;
    }   };

Log in to reply
 

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