Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 860430b

Browse files
committed
Add solution #1593
1 parent dbc90c6 commit 860430b

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,406 LeetCode solutions in JavaScript
1+
# 1,407 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1230,6 +1230,7 @@
12301230
1590|[Make Sum Divisible by P](./solutions/1590-make-sum-divisible-by-p.js)|Medium|
12311231
1591|[Strange Printer II](./solutions/1591-strange-printer-ii.js)|Hard|
12321232
1592|[Rearrange Spaces Between Words](./solutions/1592-rearrange-spaces-between-words.js)|Easy|
1233+
1593|[Split a String Into the Max Number of Unique Substrings](./solutions/1593-split-a-string-into-the-max-number-of-unique-substrings.js)|Medium|
12331234
1598|[Crawler Log Folder](./solutions/1598-crawler-log-folder.js)|Easy|
12341235
1657|[Determine if Two Strings Are Close](./solutions/1657-determine-if-two-strings-are-close.js)|Medium|
12351236
1668|[Maximum Repeating Substring](./solutions/1668-maximum-repeating-substring.js)|Easy|
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* 1593. Split a String Into the Max Number of Unique Substrings
3+
* https://leetcode.com/problems/split-a-string-into-the-max-number-of-unique-substrings/
4+
* Difficulty: Medium
5+
*
6+
* Given a string s, return the maximum number of unique substrings that the given string can
7+
* be split into.
8+
*
9+
* You can split string s into any list of non-empty substrings, where the concatenation of
10+
* the substrings forms the original string. However, you must split the substrings such that
11+
* all of them are unique.
12+
*
13+
* A substring is a contiguous sequence of characters within a string.
14+
*/
15+
16+
/**
17+
* @param {string} s
18+
* @return {number}
19+
*/
20+
var maxUniqueSplit = function(s) {
21+
return backtrack(0, new Set());
22+
23+
function backtrack(start, seen) {
24+
if (start === s.length) return seen.size;
25+
26+
let maxSplits = 0;
27+
for (let end = start + 1; end <= s.length; end++) {
28+
const substring = s.slice(start, end);
29+
if (!seen.has(substring)) {
30+
seen.add(substring);
31+
maxSplits = Math.max(maxSplits, backtrack(end, seen));
32+
seen.delete(substring);
33+
}
34+
}
35+
36+
return maxSplits;
37+
}
38+
};

0 commit comments

Comments
 (0)