首页 > 其他 > 详细

【剑指offer】【字符串】48. 最长不含重复字符的子字符串

时间:2020-05-03 19:55:42      阅读:36      评论:0      收藏:0      [点我收藏+]

class Solution {
public:
    int lengthOfLongestSubstring(string s) {
        unordered_map<char, int> hash;
        int res = 0;
        for(int i = 0, j = 0; j < s.size(); j++)
        {
            if(++hash[s[j]] > 1)
            {
                while(i < j)
                {
                    hash[s[i]]--;
                    i++;
                    if(hash[s[j]] == 1) break;
                }
            }
            res = max(res, j- i + 1);
        }
        return res;
    }
};

【剑指offer】【字符串】48. 最长不含重复字符的子字符串

原文:https://www.cnblogs.com/Trevo/p/12823063.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!