class Solution(object):
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
res = []
for c in s:
res.append(c)
longest = len(set(res))
lstr = len(s)
if longest == 1 or longest == lstr:
return longest
temp = lstr-longest + 1
while(longest > 1):
for i in range(temp):
begin = i
end = longest+i
substr = s[begin : end]
if len(set(substr)) == longest:
return longest
longest = longest - 1
temp = lstr-longest + 1
return longest
lengthOfLongestSubstring
最新推荐文章于 2023-09-20 11:18:49 发布