最长子字符串

def lengthofstr(s):
max_len = 0
if s is None or len(s) == 0:
return max_len
str_dict = {}
one_max = 0
start = 0
for i in range(len(s)):
if s[i] in str_dict and str_dict[s[i]] >= start:
start = str_dict[s[i]] + 1
one_max = i - start + 1
str_dict[s[i]] = i
max_len = max(max_len, one_max)
return max_len

s1 = input()
print(lengthofstr(s1))

你可能感兴趣的:(python基础)