3. Longest Substring Without Repeating Characters

class Solution(object):
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
sub=''
longest=''
for i in s:
if i not in sub:
sub+=i
else:
if len(sub)>=len(longest):
longest=sub
sub=sub[sub.find(i)+1:]+i
return max(len(longest),len(sub))

posted @ 2018-09-13 02:58  ffeng0312  阅读(128)  评论(0)    收藏  举报