LeetCode 3.无重复字符的最长子串

题目思路
双指针算法,只要没有出现重复的字符,就一直将i指针向后移动,如果出现了,就判断重复字符出现的字符是否是1次,然后j指针不断向后走

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        unordered_map<int,int> heap;
        int res = 0;
        for(int i = 0, j = 0;i < s.length();i++)
        {
            heap[s[i]] ++;
            while(heap[s[i]] > 1) heap[s[j ++]]--;
            res = max(res, i - j + 1);
        }
        return res;
    }
};
原文地址:https://www.cnblogs.com/zykBlog/p/13871577.html