var lengthOfLongestSubstring = function(s) {
var res = 0; // 用于存放当前最长无重复子串的长度
var str = ""; // 用于存放无重复子串
var len = s.length;
for(var i = 0; i < len; i++) {
var char = s.charAt(i);
var index = str.indexOf(char);
if(index === -1) {
str += char;
res = res < str.length ? str.length : res;
} else { //如果有当前字符串截取掉+当前字符
str = str.substr(index + 1) + char;
}
}
return res;
};
const lengthOfLongestSubstring = s => {
let len = s.length
if (len <= 1) {
return len
}
let max = 1
let record = 0
for (let i = 0; i < len; ++i) {
let index = s.indexOf(s[i], record)
if (index < i) {
record = index + 1
}
max = Math.max(max, i - record + 1)
}
return max
}
var lengthOfLongestSubstring = function(s) {
let l = 0;
let res = 0;
let map = new Map();
for (let r = 0;r < s.length;r += 1 ){
if(map.has(s[r]) && map.get(s[r]) >=l ){
l = map.get(s[r]) + 1;
}
res = Math.max(res, r - l + 1);
map.set(s[r],r);
}
return res;
};
var lengthOfLongestSubstring = function(s) { var res = 0; // 用于存放当前最长无重复子串的长度 var str = ""; // 用于存放无重复子串 var len = s.length; for(var i = 0; i < len; i++) { var char = s.charAt(i); var index = str.indexOf(char); if(inde...