题目:
https://leetcode.com/problems/maximum-product-of-word-lengths/
提示:使用位操作
class Solution
{
public:
int maxProduct(vector<string>& words)
{
if(words.size()<=1)
return 0;
vector<int> help(words.size(),0);
for(int i=0;i<words.size();++i)
{
for(auto c:words[i])
{
setone(help[i],c-'a');
}
}
int res=0;
for(int i=0;i<words.size()-1;++i)
{
for(int j=i+1;j<words.size();++j)
{
if(!(help[i]&help[j]))
{
int tmp=(words[i].length())*(words[j].length());
res=max(res,tmp);
}
}
}
return res;
}
void setone(int &n,int i)
{
n=n|(1<<(31-i));
}
};