题解 | #最长不含重复字符的子字符串#

最长不含重复字符的子字符串

https://www.nowcoder.com/practice/48d2ff79b8564c40a50fa79f9d5fa9c7

    public int lengthOfLongestSubstring (String s) {
        char[] str = s.toCharArray();
        int max = 0;
        int begin = 0;
        HashMap<Character,Integer> m = new HashMap<Character,Integer>();
        for(int i = 0; i<str.length; i++){
            if(m.containsKey(str[i]) && m.get(str[i])>=begin){
                begin = m.get(str[i])+1;
            }
            m.put(str[i],i);
            max = Math.max(max,i-begin+1);
        }
        return max;
    }

全部评论

相关推荐

10-20 11:11
辽宁大学 营销
点赞 评论 收藏
分享
09-16 14:01
井冈山大学 Java
肖先生~:兄弟们,我发的她都点赞了,但是就是不给我微信
秋招被确诊为……
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务