What's wrong with my solution?


  • 0
    E

    public static int lengthOfLongestSubstring(String s) {

        int maxLength = 0;
        int tempMax = 0;
        
        for(int i = 0; i < s.length(); i++) {
            
           ++tempMax;
            
            if(i-1 > -1){
            
            	if(s.charAt(i) == s.charAt(i-1))
            		tempMax = 1;
            
            }
                  
            if(tempMax > maxLength)  
                maxLength = tempMax;
        }
        
        return maxLength;
    

    }


Log in to reply
 

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