JS 12 Lines Solution


  • 0
    C
    var lengthOfLongestSubstring = function(s) {
        let start = 0, end = 0, counts = [] 
        for (let end=0 ; end<s.length ; end++ ){
            if (s.substring(start,end).includes(s[end])){
                counts.push(end-start)
                start = s.substring(start,end).indexOf(s[end])+start+1
            }
        }
        counts.push(s.length-start)
        const max = Math.max(...counts)
        return max
    };
    

Log in to reply
 

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