97 days: reference to offer 48, the longest does not contain repeated character substring
Address: leetcode-cn.com/problems/zu…
Sliding Windows
var lengthOfLongestSubstring = function(s) {
s = s.split('');
const n = s.length;
let max = 0;
for(let i = 0; i < n - max; i++)
{
let res = [];
let j = i;
while(res.indexOf(s[j]) === -1 && j < n)
{
res.push(s[j]);
j++;
}
max = Math.max(max, res.length);
}
return max;
};
Copy the code
The code is rather jumbled
Execution time: 568 ms, beating 5.06% of all JavaScript commits
Memory consumption: 44.1 MB, beating 18.13% of all JavaScript commits