LeetCode地址
算法难度
中等
JS代码
/**
* @param {string} s
* @return {number}
*/
var lengthOfLongestSubstring = function(s) {
let stack = {}, m = 0, j = 0, max = 0
for (let i = 0, len = s.length; i < len; i++) {
if (m = stack[s[i]]) j = Math.max(m, j)
stack[s[i]] = i + 1
max = Math.max(max, i - j + 1)
}
return max
};