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))

浙公网安备 33010602011771号