int lengthOfLongestSubstring(string s
){
int start(0),end(0),res(0);
unordered_map
<char,int> m
;
while(end
<s
.size()){
if(m
.find(s
[end
])!=m
.end()&&m
[s
[end
]]>=start
){
res
=max(res
,end
-start
);
start
=m
[s
[end
]]+1;
}
else
res
=max(res
,end
-start
+1);
m
[s
[end
]]=end
;
end
++;
}
return res
;
}
转载请注明原文地址:https://tech.qufami.com/read-251.html