class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
if not s:
return 0
max_len = 1
l_one = 0
l_two = 1
tmp_set = set()
while l_one < len(s)-1 and l_two <= len(s)-1:
if s[l_one] not in tmp_set:
tmp_set.add(s[l_one])
if s[l_two] not in tmp_set:
tmp_set.add(s[l_two])
l_two += 1
tmp_len = l_two - l_one
if tmp_len > max_len:
max_len = tmp_len
else:
l_one += 1
l_two = l_one + 1
tmp_set = set()
return max_len
3,无重复字符的最长子串
最新推荐文章于 2020-07-01 18:45:27 发布