用滑动窗口
class Solution:
def lengthOfLongestSubstring(self, s):
i, j, ans = 0, 0, 0
len_s = len(s)
max_str = ''
while j < len_s:
if not s[j] in max_str:
max_str += s[j]
j += 1
ans = max(ans, j-i)
else:
max_str = max_str[1:]
i += 1
return ans