// ------------------最长无重复子串---------------------------- var lengthOfLongestSubstring = function(s) { let max = 0 let left = 0 let right = 1 let l = 0 let r = 0 if (s.length === 0 || s.length === 1) return s.length while (right < s.length) { let sub = s.slice(left, right) if (sub.indexOf(s[right]) > -1) { left++ continue } else { right++ } if (right - left > max) { max = right - left l = left r = right } } console.log(s.slice(l, r)) return s.slice(l, r).length };