双指针(滑动窗口算法) 区间[j,i] i往后走,j只有两种选择原地或者往后走
 
class Solution {
public:
    int lengthOfLongestSubstring(string s
) {
        unordered_map
<char, int> hash
;
        int res 
= 0;
        for(int i 
= 0, j 
=0; i 
< s
.size(); i 
++){
            hash
[s
[i
]] ++;
            while(hash
[s
[i
]] > 1) hash
[s
[j
++]] --;
            res 
= max(res
, i 
- j 
+ 1);
        }
        return res
;
    }
};
                
                
                
        
    
转载请注明原文地址:https://tech.qufami.com/read-19402.html