9 line JavaScript solution


  • 19
    L
    function lengthOfLongestSubstring(s) {
        const map = {};
        var left = 0;
        
        return s.split('').reduce((max, v, i) => {
            left = map[v] >= left ? map[v] + 1 : left;
            map[v] = i;
            return Math.max(max, i - left + 1);
        }, 0);
    }

  • 0
    H
    This post is deleted!

Log in to reply
 

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