題目描述:
https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/
解題思路:
代碼實現:
class Solution {
public:
int lengthOfLongestSubstring(string s) {
int len = 0, left = -1;
for(int i = 0; i < s.size(); i++){
if(m.count(s[i]) && m[s[i]] > left){
left = m[s[i]];
}
m[s[i]] = i;
len = max(len, i - left);
}
return len;
}
private:
unordered_map<int, int> m;
};