Clear and easily understanding


  • 7
    L
    int maxProduct(vector<string>& words) 
    {
        vector<int> keys(words.size(), 0);
        
        for(int i=0; i<words.size(); i++)
        {
            for(auto &c: words[i])
            {
                keys[i] |= 1<<(c-'a');
            }
        }
        
        int res = 0;
        
        for(int i=0; i<words.size(); i++)
        {
            for(int j=i+1; j<words.size(); j++)
            {
                if((keys[i] & keys[j]) == 0 && words[i].size()*words[j].size() > res)
                {
                    res = words[i].size()*words[j].size();
                }
            }
        }
        
        return res;
        
    }

  • 0
    Y

    is this solution exceed time?


  • 0
    L

    No exceed time, at least when I submit, otherwise, I would not publish it


Log in to reply
 

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