We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 419d34c commit 20470c3Copy full SHA for 20470c3
longest-substring-without-repeating-characters/jdy8739.js
@@ -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