https://leetcode-cn.com/problems/zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof/
双指针滑动窗口,首先初始化left和right都在开头,然后固定left不动,让right不断后移,每后移一步,就判断当前字符是否跟窗口内字符重复,如果有重复,则先固定right不动,然后left不断后移,left后移的过程中窗口内的字符不断减少,直到减少到right处的字符在窗口内已不重复,然后继续固定left让right后移。
int lengthOfLongestSubstring(string s){
if(s.size() == 0) return 0;
int maxlength = 0, temp = 0;
int left = 0, right = 0;
unordered_set<char> sset;
while(left < s.size()){
while(right < s.size() && !sset.count(s[right])){
sset.insert(s[right++]);
}
temp = sset.size();
max_length = max(maxlength, temp);
if(right == s.size()) break;
sset.erase(s[left++]);
}
return maxlength;
}