【中等】无重复字符的最长子数组

【中等】无重复字符的最长子数组_第1张图片
【中等】无重复字符的最长子数组_第2张图片

class Solution {
private:
    unordered_map<char, int> window;
public:
    int lengthOfLongestSubstring(string s) {
        int left = 0, right = 0, len = 0;
        while (right < s.size())
        {
            char c = s[right++];
            window[c]++;
            while (window[c] > 1)
            {
                char d = s[left++];
                window[d]--;
            }
            if (right - left > len)
                len = right - left;
        }
        return len;
    }
};

你可能感兴趣的:(#,滑动窗口,leetcode,算法,职场和发展)