-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path1239.cpp
More file actions
27 lines (27 loc) · 824 Bytes
/
1239.cpp
File metadata and controls
27 lines (27 loc) · 824 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) {
int n = arr.size();
int res = 0;
for (int state = 1; state < (1 << n); ++state) {
vector<bool> hash(26, false);
bool valid = true;
int length = 0;
for (int i = 0; i < n && valid; ++i) {
if ((state & (1 << i)) == (1 << i)) {
for (auto& c : arr[i]) {
if (hash[c - 'a']) {
valid = false;
break;
}
hash[c - 'a'] = true;
length++;
}
}
if (valid) res = max(res, length);
else break;
}
}
return res;
}
};