forked from luliyucoordinate/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1239.cpp
More file actions
29 lines (27 loc) · 670 Bytes
/
Copy path1239.cpp
File metadata and controls
29 lines (27 loc) · 670 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
class Solution
{
public:
typedef bitset<26> charBits;
int maxLength(vector<string>& arr)
{
dfs(arr, 0, "");
return res;
}
private:
int res = 0;
void dfs(vector<string>& arr, int index, string path)
{
auto bp = toBitset(path);
int lsp = bp.count(), lp = path.size();
if (lp == lsp) res = max(res, lp);
if (index == arr.size() || lsp != lp) return;
for (int i = index; i < arr.size(); i++)
dfs(arr, i + 1, path + arr[i]);
}
charBits toBitset(const string& s)
{
charBits bs;
for (char c : s) bs.set(c - 'a');
return bs;
}
};