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