Skip to content

Commit dae712b

Browse files
committed
Time: 2277 ms (5.26%), Space: 442.7 MB (5.26%) - LeetHub
1 parent 9566737 commit dae712b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class Solution {
2+
public:
3+
int maxUniqueSplit(string s) {
4+
int n = s.size();
5+
int ans = 0;
6+
for (int i = 0; i < (1 << n); i++) {
7+
vector<int> temp(n);
8+
for (int j = 0; j < n; j++) {
9+
if ((1 << j) & i) {
10+
temp[j] = 1;
11+
}
12+
}
13+
set<string> st;
14+
string x;
15+
int cnt = 0;
16+
for (int i = 0; i < n; i++) {
17+
x += s[i];
18+
if (temp[i] == 0) {
19+
cnt++;
20+
st.insert(x);
21+
x.clear();
22+
}
23+
}
24+
if (x.size()) {
25+
st.insert(x);
26+
cnt++;
27+
}
28+
if (st.size() == cnt) {
29+
ans = max(ans, cnt);
30+
}
31+
}
32+
return ans;
33+
}
34+
};

0 commit comments

Comments
 (0)