题解 | 包含不超过两种字符的最长子串
s=input() #找出最多包含两种字符的最长子串 t def long_str(s:str)->int: left=0 n=len(s) res=0 dic={} for right in range(n): if s[right] not in dic: dic[s[right]]=1 else: dic[s[right]]+=1 while len(dic)>2: dic[s[left]]-=1 if dic[s[left]]==0: del dic[s[left]] left+=1 res=max(res,right-left+1) return res print(long_str(s))