class Solution {
public:
int lengthOfLongestSubstring(string s) {
//初始条件
if(s.length()==0) return 0;
int left = 0, right = 0;
map<char, int> window;
int match = 0;
int res = INT_MIN;
while(right < s.length()) {
window[s[right]]++;
if(window[s[right]]==1) match++;
right++;
while(right-left!=match) {
//当有重复时再去移动left++.
if(s[left]!=s[right-1]) {
match--;
}
window[s[left]]--;
left++;
}
//保证所有res比较的都是条件满足的.
res = max(res, match);
}
return res;
}
};