-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday2
More file actions
27 lines (23 loc) · 688 Bytes
/
day2
File metadata and controls
27 lines (23 loc) · 688 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
class Solution {
public:
int maxLength(vector<string>& arr) {
vector<int> dp = {0};
int res = 0;
for (const string& s : arr) {
int a = 0, dup = 0;
for (char c : s) {
dup |= a & (1 << (c - 'a'));
a |= 1 << (c - 'a');
}
if (dup > 0)
continue;
for (int i = dp.size() - 1; i >= 0; i--) {
if ((dp[i] & a) > 0)
continue;
dp.push_back(dp[i] | a);
res = max(res, __builtin_popcount(dp[i] | a));
}
}
return res;
}
};