deno.land / x / masx200_leetcode_test@10.6.5 / longest-substring-without-repeating-characters / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
function lengthOfLongestSubstring(s: string): number { const occ = new Set(); let right = -1; let ans = 0; const n = s.length; for (const i of Array.prototype.keys.call(s)) { if (i !== 0) { occ.delete(s[i - 1]); } while (right + 1 < n && !occ.has(s[right + 1])) { occ.add(s[right + 1]); right++; } ans = Math.max(ans, right - i + 1); } return ans;}export default lengthOfLongestSubstring;
masx200_leetcode_test

Version Info

Tagged at
a year ago