-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathDay29.cpp
More file actions
36 lines (36 loc) · 802 Bytes
/
Day29.cpp
File metadata and controls
36 lines (36 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Solution {
public:
int findState(string s)
{
int state=0;
for(char &ch:s)
{
state|=(1<<(ch-'a'));
}
return state;
}
int maxProduct(vector<string>& words) {
int n=words.size();
vector<int> state;
for(auto a:words)
{
state.push_back(findState(a));
}
int ans=INT_MIN;
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if((state[i]&state[j])==0)
{
int l=words[i].length()*words[j].length();
if(ans<l)
{
ans=l;
}
}
}
}
return ans==INT_MIN?0:ans;
}
};