双指针--无重复最长子串

传送门:无重复最长子串

题面分析

双指针--无重复最长子串_第1张图片
AC代码

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        
        unordered_map hash;
        int res = 0;
        for(int i=0,j=0;j1) hash[s[i++]]--;
            res = max(res,j-i+1);
        }

        return res;
    }
};

 

你可能感兴趣的:(双指针--无重复最长子串)