my clean javascript solution


  • 0
    3
    /**
     * @param {string} s
     * @return {number}
     */
    var lengthOfLongestSubstring = function(s) {
        var p = 0,q=0;
        var longest = 0;
        var hs = {};
        while(p<s.length){
            if(!hs.hasOwnProperty(s[q])&&q<s.length){
                hs[s[q]] = 1;
                q++;
                longest = Math.max(longest,q-p);
            } else {
                //hs.splice(0,1);
                delete hs[s[p]];
                p++;
            }
            
        }
        return longest;
    };
    

Log in to reply
 

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