Java最大不重复子串

Given a string, find the length of the longest substring without repeating characters。

 public static int lengthOfLongestSubstring(String s) {
        int result=0;
        for(int i=0;i<s.length();i++){
            int count=0;
            HashMap<Character,Integer> map=new HashMap<>();
            for(int j=i;j<s.length();j++){
                if(!map.containsKey(s.charAt(j))){
                    map.put(s.charAt(j),1);
                    count++;
                }else{
                    break;
                }

            }
            if(count>=result){
                result=count;
            }
        }
        return result;
    };

猜你喜欢

转载自blog.csdn.net/weixin_43927892/article/details/104236337