Simple solution in JavaScript


  • 0
    T

    var lengthOfLongestSubstring = function(s) {

        var length = s.length;
        str ="";
        max = 0;
        for(i=0;i<length;i++){
            point = str.indexOf(s[i]);
            if(point != -1){
                if(max < str.length){
                        max =  str.length;
                }
                str = str.substring(point+1);
            }
            str = str + s[i];
        }
        if(max < str.length){
                    max =  str.length;
        }
    
        return max
    

    };


Log in to reply
 

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