说是滑动窗口也行,说是双指针也行
其核心在于,以left开头
当走到此right时产生了重复,那么left到right不可能重复
所以将left移动到再次不重复的地方,
再继续往下走
def fun1(s):
#使用双指针
left=0
right=0
select={}
max_=0
while right<len(s):
cur=s[right]
if (cur not in select) or select[cur]==0:
select[cur]=1
max_=max(max_,right-left+1)
right+=1
else:
select[s[left]]=0
left+=1
return max_
print(fun1("abcabcbb"))