无重复字符串里的最长子串
这道题是让我们找到不含重复字符串里面最长的字符串的长度,红色这里应该怎么改呀?谢谢啦class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
ans=''
i=0
ma=0
dic={}
if s=='':
return 0
while i<=len(s):
for a in s:
if a not in ans:
ans+=a
else:
break
ma=len(ans)
i+=1
dic.setdefault(ans,ma)
print(dic)
return max(dic.values()) 本帖最后由 逃兵 于 2020-11-29 17:34 编辑
break改成continue
附源码
class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
ans=''
i=0
ma=0
dic={}
if s=='':
return 0
while i<=len(s):
for a in s:
if a not in ans:
ans+=a
else:
continue
ma=len(ans)
i+=1
dic.setdefault(ans,ma)
print(dic)
return max(dic.values())
页:
[1]