Skip to content

Commit 2d41eb4

Browse files
committed
Time: 158 ms (90.58%), Space: 16.5 MB (55.61%) - LeetHub
1 parent 74247ab commit 2d41eb4

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution:
2+
def backtrack(self, s: str, start: int, seen: set) -> int:
3+
if start == len(s):
4+
return 0
5+
6+
maxCount = 0
7+
for end in range(start + 1, len(s) + 1):
8+
subString = s[start:end]
9+
if subString not in seen:
10+
seen.add(subString)
11+
maxCount = max(maxCount, 1 + self.backtrack(s, end, seen))
12+
seen.remove(subString)
13+
14+
return maxCount
15+
16+
def maxUniqueSplit(self, s: str) -> int:
17+
seen = set()
18+
return self.backtrack(s, 0, seen)
19+
20+
21+
s = "ababccc"
22+
print(Solution().maxUniqueSplit(s))

0 commit comments

Comments
 (0)