mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
Add leetcode 318
This commit is contained in:
parent
5e80796721
commit
9952c85bd1
26
LeetCode-CN/318.cpp
Normal file
26
LeetCode-CN/318.cpp
Normal file
|
@ -0,0 +1,26 @@
|
|||
class Solution {
|
||||
public:
|
||||
int maxProduct(vector<string>& words) {
|
||||
const int N = words.size();
|
||||
vector<int32_t> mark;
|
||||
for (auto& s : words) {
|
||||
int32_t m = 0;
|
||||
for (auto& c : s) {
|
||||
m |= 1 << (c - 'a');
|
||||
}
|
||||
mark.push_back(m);
|
||||
}
|
||||
|
||||
size_t ret = 0;
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
for (int j = i + 1; j < N; j++)
|
||||
{
|
||||
if (!(mark[i] & mark[j])) {
|
||||
ret = max(ret, words[i].size() * words[j].size());
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user