题目来源于LeetCode
给定一个字符串 s
,请你找出其中不含有重复字符的最长子串的长度。
s = 'abcabcbb'
left, right, length, max_length = 0, 0, 0, 0
hashTable = set()
while right < len(s):
if s[right] not in hashTable:
hashTable.add(s[right])
right += 1
length += 1
if length > max_length:
max_length = length
else:
while s[right] in hashTable:
hashTable.remove(s[left])
left += 1
length -= 1
hashTable.add(s[right])
right += 1
length += 1
print(max_length) # 3