class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
count = 0
start = -1
d = {} #key保存字符,value保存字符坐标
for i,c in enumerate(s): #i:字符下标,c:字符
if c in d and start<d[c]: #如果当前字符在字典中保存过
start = d[c] #那么记录一段新的子串起点位置
d[c] = i #更新当前字符下标
else: # 如果c不在字典中
d[c] = i #那么保存c到字典
if count < i-start: #如果当前字串比之前字串长
count = i-start #那么更新长度
return count