【leetcode】【hot100】3無重複字符的最長子串

題目描述:

https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/

解題思路: 

代碼實現:

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        int len = 0, left = -1;
        for(int i = 0; i < s.size(); i++){
            if(m.count(s[i]) && m[s[i]] > left){
                left = m[s[i]];
            }
            m[s[i]] = i;
            len = max(len, i - left);
        }
        return len;
    }
private:
    unordered_map<int, int> m;
};

 參考:https://www.cnblogs.com/grandyang/p/4480780.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章