def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
if len(s)==1 or len(s)==0:return len(s)
m=""
longest=""
l=list(s)
for i in range(len(l)):
if m.find(l[i])==-1:
m+=l[i]
else:
if len(m)>len(longest):
longest=m
j=i+1
i=i-len(m)+m.find(l[i])+1
m="".join(l[i:j])
if len(m)>len(longest):
longest=m
return len(longest)
无重复字符的最长子串
最新推荐文章于 2024-07-16 23:15:32 发布