# 例如对于 arabcacfr,最长不含重复字符的子字符串为 acfr,长度为 4。
def lengthOfLongestSubstring(s="arabcacfr"):
def dfs(s, dp):
if len(s) == 0:
print(dp)
return len(dp)
if s[:1] in dp:
print(dp)
return max(len(dp), dfs(s, []))
dpcopy = dp.copy()
dpcopy.append(s[:1])
return dfs(s[1:], dpcopy)
return dfs(s, [])
print(lengthOfLongestSubstring())
output:
['a', 'r']
['a', 'b', 'c']
['a', 'c', 'f', 'r']
4
标签:字符,return,48,dfs,print,len,字符串,dp,dpcopy
From: https://www.cnblogs.com/aolob/p/17596006.html