My java solution


  • 0
    Z

    Map<Character, Integer> temp = new HashMap();

        int current=1;
        int max=0;
            for(int i=1;i<s.length()+1;i++){
                if(temp.containsKey(s.charAt(i-1))){
                     current=Math.max(temp.get(s.charAt(i-1))+1,current);
                }
                max = Math.max(max,i-current+1);
                temp.put(s.charAt(i-1),i);
            }
        return max;

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.