/*
* @lc app=leetcode id=3 lang=typescript
*
* [3] Longest Substring Without Repeating Characters
*/
// @lc code=start
function lengthOfLongestSubstring(s: string): number {
let max = 0;
let l = 0;
let slideWindow = [] as string[];
for (let r = 0; r < s.length; r++) {
// move left to the position that s[r] is not included in the slideWindow
while (slideWindow.includes(s[r])) {
slideWindow.shift();
l++;
}
// push current right element to the slideWindow
slideWindow.push(s[r]);
// compare to the current max value with slideWindow's length
max = Math.max(max, slideWindow.length);
}
return max;
};
// @lc code=end
3 Longest Substring Without Repeating Characters