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 9defd5e commit 516540eCopy full SHA for 516540e
longest-substring-without-repeating-characters/gwbaik9717.js
@@ -0,0 +1,30 @@
1
+// n: len(s)
2
+// Time complexity: O(n^2)
3
+// Space complexity: O(n)
4
+
5
+/**
6
+ * @param {string} s
7
+ * @return {number}
8
+ */
9
+var lengthOfLongestSubstring = function (s) {
10
+ let answer = 0;
11
+ const map = new Map();
12
13
+ for (let i = 0; i < s.length; i++) {
14
+ const chr = s[i];
15
16
+ if (map.has(chr)) {
17
+ const temp = map.get(chr);
18
+ for (const [key, value] of map) {
19
+ if (value <= temp) {
20
+ map.delete(key);
21
+ }
22
23
24
25
+ map.set(chr, i);
26
+ answer = Math.max(answer, map.size);
27
28
29
+ return answer;
30
+};
0 commit comments