java无重负字符的最长字串

left=Math.max(left,rightCharindex);有逻辑错误,我将它注释之后用

if(rightCharindex==0){

        }else if(left>rightCharindex){
            
        }else {
            left=rightCharindex+1;
        }

结果反而报错了

问题相关代码,请勿粘贴截图

class Solution {
    public int lengthOfLongestSubstring(String s) {
        int n=s.length();
        int left=0,right=0;
        if(n<=1) return n;
        int maxLen=1;
        Map<Character, Integer> window = new HashMap<>();
        while(right<n){
            char rightChar = s.charAt(right);
            int rightCharindex = window.getOrDefault(rightChar, 0);
            //left=Math.max(left,rightCharindex);
            if(rightCharindex==0){ 

            }else if(left>rightCharindex){
                
            }else {
                left=rightCharindex+1;
            }
            maxLen=Math.max(maxLen,right - left + 1);
            window.put(rightChar,right+1);
            right++;

        }
        return maxLen;
    }
}
运行结果及报错内容

img

我的解答思路和尝试过的方法
我想要达到的结果

检查逻辑,注意细节,先写出可执行代码在进行优化

你这个没报错啊,是结果不对