思路
利用set 循环滚一边
源码
/** * @param {string} s * @return {number} */var lengthOfLongestSubstring = function(s) { let len = s.length; let max = 0; for(let i = 0; i < len; ++i){ let set = new Set(); for(let j = i; j < len; ++j){ if(set.has(s[j])){ let size = set.size; max = size > max ? size : max; break; } else{ set.add(s[j]); } } let size = set.size; max = size > max ? size : max; } return max;};复制代码