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 6dd8755 commit d819cc5Copy full SHA for d819cc5
longest-substring-without-repeating-characters/sunjae95.js
@@ -0,0 +1,23 @@
1
+/**
2
+ * @description
3
+ * brainstorming:
4
+ * hash table + two pointer
5
+ *
6
+ * n = length of s
7
+ * time complexity: O(n)
8
+ * space complexity: O(n)
9
+ */
10
+var lengthOfLongestSubstring = function (s) {
11
+ const map = new Map();
12
+ let answer = 0;
13
+ let start = 0;
14
+ let end = 0;
15
+ for (let i = 0; i < s.length; i++) {
16
+ if (map.has(s[i])) start = Math.max(map.get(s[i]) + 1, start);
17
+ map.set(s[i], i);
18
+ end += 1;
19
+ answer = Math.max(answer, end - start);
20
+ }
21
+
22
+ return answer;
23
+};
0 commit comments