File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change 1
- # 1,406 LeetCode solutions in JavaScript
1
+ # 1,407 LeetCode solutions in JavaScript
2
2
3
3
[ https://leetcodejavascript.com ] ( https://leetcodejavascript.com )
4
4
1230
1230
1590|[ Make Sum Divisible by P] ( ./solutions/1590-make-sum-divisible-by-p.js ) |Medium|
1231
1231
1591|[ Strange Printer II] ( ./solutions/1591-strange-printer-ii.js ) |Hard|
1232
1232
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|
1233
1234
1598|[ Crawler Log Folder] ( ./solutions/1598-crawler-log-folder.js ) |Easy|
1234
1235
1657|[ Determine if Two Strings Are Close] ( ./solutions/1657-determine-if-two-strings-are-close.js ) |Medium|
1235
1236
1668|[ Maximum Repeating Substring] ( ./solutions/1668-maximum-repeating-substring.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments