[leetcode]3. Longest Substring Without Repeating Characters

旧城冷巷雨未停 提交于 2019-11-26 05:33:59
class Solution {
    public int lengthOfLongestSubstring(String s) {
        int [] map = new int[128];
        int len = Integer.MIN_VALUE;
        int start = 0;
        int end = 0;
        while(end < s.length()){
            int c = s.charAt(end);
            if(map[c] == 0){
                map[c]++;
                if(end - start + 1 >= len){
                    len = end - start + 1;
                }
                
                end++;
                
            }
            else{
                map[s.charAt(start)] = 0;
                start++;
            }
            
        }
        if(len == Integer.MIN_VALUE) return 0;
        return len;
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!