题解 | #最长不含重复字符的子字符串#
最长不含重复字符的子字符串
https://www.nowcoder.com/practice/48d2ff79b8564c40a50fa79f9d5fa9c7
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param s string字符串 * @return int整型 */ function lengthOfLongestSubstring( s ) { // write code here let max = 0 const map = {} let left = 0 let right = 0 while (right < s.length) { const rightV = s[right] if (map[rightV]) { map[rightV]++ } else { map[rightV] = 1 } while (map[rightV] > 1) { map[s[left]]-- left++ } max = Math.max(max, right - left + 1) right++ } return max } module.exports = { lengthOfLongestSubstring : lengthOfLongestSubstring };