class Solution:
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
res = 0
u = ''
for i in range(len(s)):
k = s[i]
if k not in u:
u+=k
res = max(len(u),res)
else:
index = u.find(k)
u = u[index+1:]+k
return res
str1 = "aab"
str2 = "a"
a = Solution()
print(a.lengthOfLongestSubstring(str1))
python无重复最长子串
最新推荐文章于 2025-06-25 17:16:11 发布