-
解題思路
先是循環(huán)字符串s中每一個(gè)值烁落,然后分別和臨時(shí)列表res中的數(shù)值進(jìn)行判斷對比豌注,如果重復(fù)了,就把重復(fù)的前面給截取出來轧铁,如果沒有重復(fù)就追加到末尾
-
代碼如下:
def lengthOfLongestSubstring(s):
res = []
tmp = []
for i in s:
if i in res:
index = res.index(i) + 1
res = res[index:]
res.append(i)
continue
else:
res.append(i)
if len(tmp) < len(res):
tmp = res
print(tmp)