Skip to content

Commit 20470c3

Browse files
committed
longest-substring-without-repeating-characters solution
1 parent 419d34c commit 20470c3

File tree

1 file changed

+36
-0
lines changed
  • longest-substring-without-repeating-characters

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* @param {string} s
3+
* @return {number}
4+
*/
5+
var lengthOfLongestSubstring = function(s) {
6+
let start = 0;
7+
let end = 0;
8+
9+
const set = new Set();
10+
11+
let max = 0;
12+
13+
while (end < s.length) {
14+
const char = s[end];
15+
16+
if (set.has(char)) {
17+
set.delete(s[start]);
18+
19+
start++;
20+
} else {
21+
set.add(char);
22+
23+
end++;
24+
}
25+
26+
max = Math.max(max, set.size);
27+
}
28+
29+
return max;
30+
};
31+
32+
//
33+
//
34+
35+
36+

0 commit comments

Comments
 (0)