题目传送
暴力然后记忆化即可
AC代码
class Solution {
public:
int maxProduct(vector<string>& words) {
int len = words.size(),Max = 0;
int vis[len+5][30];
for(int i = 0;i < len;i++){
for(int j = 0;j < 30;j++){
vis[i][j] = 0;
}
}
for(int i = 0;i < len;i++){
for(int j = 0;j < words[i].size();j++){
vis[i][words[i][j]-'a'] = 1;
}
}
for(int i = 0;i < len;i++){
for(int j = i+1;j < len;j++){
int flag = 1;
for(int k = 0;k < 26;k++){
if(!((vis[i][k] == 0 && vis[j][k] == 0) || vis[i][k] != vis[j][k])){
flag = 0;
}
}
if(flag){
int a = words[i].size()*words[j].size();
Max = max(Max,a);
}
}
}
return Max;
}
};