3.Longest Substring Without Repeating Characters
作者:互联网
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int res = 0, left = -1, n = s.size();
unordered_map<int, int> m;
for (int i = 0; i < n; ++i) {
if (m.count(s[i]) && m[s[i]] > left) {
left = m[s[i]];
}
m[s[i]] = i;
res = max(res, i - left);
}
return res;
}
};
标签:count,map,return,int,res,Substring,Without,Repeating,left 来源: https://www.cnblogs.com/smallredness/p/10671388.html