6-lines simple Javascript solution, O(n)


  • 1
    C
    var lengthOfLongestSubstring = function(s) {
        let result = 0, t = []
        for (var i = 0; i < s.length; i++) {
            t = t.slice(t.indexOf(s[i]) + 1)
            result = Math.max(t.push(s[i]), result)
        }
        return result
    }
    

Log in to reply
 

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