Skip to content

Commit ad3a650

Browse files
authored
Create 1593-split-a-string-into-the-max-number-of-unique-substrings.js
1 parent 822d7d3 commit ad3a650

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
const maxUniqueSplit = function(s) {
6+
return bt(s, '', 0, new Set())
7+
};
8+
9+
function bt(str, cur, idx, useds) {
10+
if(idx === str.length) return useds.size
11+
cur += str[idx]
12+
if(useds.has(cur)) return bt(str, cur, idx +1, useds)
13+
else {
14+
let ans = 0
15+
useds.add(cur)
16+
ans = Math.max(ans, bt(str, '', idx+1, useds))
17+
useds.delete(cur)
18+
ans = Math.max(ans, bt(str, cur, idx+1, useds))
19+
return ans
20+
}
21+
}

0 commit comments

Comments
 (0)