def func(s):
if s == "":
return 0
i = 0
dict1 = {}
list1 = []
for j in range(len(s)):
if s[j] not in dict1:
dict1[s[j]] = j
if j == len(s)-1:
list1.append(j-i+1)
else:
list1.append(j-i)
m = dict1[s[j]]
for key in s[i:dict1[s[j]]+1]:
dict1.pop(key)
dict1[s[j]] = j
i = m + 1
return max(list1)
将就着看看吧,差点把自己绕进去。。有什么好的写法请推荐