题目描述
blablabla
样例
blablabla
算法1(滑动窗口)
class Solution {
public:
int longestSubstringWithoutDuplication(string s) {
unordered_map<char,int> windows;
int res=0;
int len=s.size();
int left=0,right=0;
while (right<len) {
char c=s[right];
windows[c]++;
right++;
while (windows[c]>1) {
char d=s[left];
windows[d]--;
left++;
}
res=max(res,right-left);
}
return res;
}
};