题解 | 最长不含重复字符的子字符串
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param s string字符串 # @return int整型 # class Solution: def lengthOfLongestSubstring(self , s: str) -> int: # write code here n=len(s) dic={} left=0 res=0 for right,x in enumerate(s): if x not in dic: dic[x]=1 else: dic[x]+=1 while dic[s[right]]>=2: dic[s[left]]-=1 left+=1 res=max(res,right-left+1) return res