1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
* @param {string} s
* @return {number}
*/
var lengthOfLongestSubstring = function(s) {
let map = [];
let max = 0
for(let i = 0; i < s.length; i++){
const idx = map.indexOf(s[i])
if (idx != -1) map = map.slice(idx+1)
map.push(s[i])
max = Math.max(max, map.length)
}
max = Math.max(max, map.length)
return max
};