Re: [闲聊] 每日leetcode

楼主: DJYOMIYAHINA (通通打死)   2024-10-21 23:18:21
兄弟们
这边直接dfs
还是这叫做backtracking
不知道
咱们直接干下去
def maxUniqueSplit(self, s: str) -> int:
ans = 0
def dfs(visited, idx):
nonlocal ans
if idx==len(s):
ans = max(ans, len(visited))
for i in range(idx+1, len(s)+1):
if s[idx:i] not in visited:
visited.add(s[idx:i])
dfs(visited, i)
visited.remove(s[idx:i])
dfs(set(), 0)
return ans
作者: sustainer123 (caster)   2023-10-21 23:18:00
大佬

Links booklink

Contact Us: admin [ a t ] ucptt.com