blob: b364d26e4898ecdae843dd6ea5ec5f71a8c32369 (
plain)
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
|
#include "leetcode.h"
class Solution {
public:
int maxLength(vector<string> &arr) {
int ans = 0;
vector<bitset<26>> unique;
for (auto s : arr) {
bitset<26> b;
for (char ch : s)
b.set(ch - 'a');
if (b.count() == s.size())
unique.push_back(b);
}
vector<bitset<26>> concat = {bitset<26>()};
for (auto &u : unique)
for (int i = concat.size() - 1; i >= 0; i--)
if ((concat[i] & u).none()) {
concat.push_back(concat[i] | u);
ans = max(ans, (concat[i].count() + u.count()));
}
return ans;
}
};
int main() {
Solution obj;
vector<string> arr = {"un", "iq", "ue"};
cout << obj.maxLength(arr);
}
|