class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
if len(s)==0 or len(s)==1:
return len(s)
temp=[]
maxlen=0
for i in s:
if i in temp:
if len(temp)>maxlen:
maxlen=len(temp)
temp=temp[temp.index(i) + 1:]#把重复之前的都删掉,例如dabc,i=a删去da
temp.append(i)
if len(temp) > maxlen:
maxlen = len(temp)
return maxlen
LeetCode-3.无重复字符的最长子串(Python)
最新推荐文章于 2024-07-24 11:56:55 发布