class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
lst = list(s)
maxl = 0
sublst = []
for i in lst:
if i in sublst:
pos = sublst.index(i)
sublst = sublst[pos+1:]
sublst.append(i)
else:
sublst.append(i)
maxl = max(len(sublst),maxl)
return maxl
leetcode-3无重复字符的最长字符串
最新推荐文章于 2024-08-29 19:34:59 发布