We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9566737 commit dae712bCopy full SHA for dae712b
1593-split-a-string-into-the-max-number-of-unique-substrings/1593-split-a-string-into-the-max-number-of-unique-substrings.cpp
@@ -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
26
27
28
+ if (st.size() == cnt) {
29
+ ans = max(ans, cnt);
30
31
32
+ return ans;
33
34
+};
0 commit comments