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 797b86b commit edb6e8cCopy full SHA for edb6e8c
longest-substring-without-repeating-characters/nhistory.js
@@ -0,0 +1,19 @@
1
+var lengthOfLongestSubstring = function (s) {
2
+ // Create map to store character from string
3
+ let map = new Map();
4
+ let maxLen = 0;
5
+ let start = 0;
6
+
7
+ for (let end = 0; end < s.length; end++) {
8
+ if (map.has(s[end])) {
9
+ // Move the start pointer to the right of the previous position of current character
10
+ start = Math.max(map.get(s[end]) + 1, start);
11
+ }
12
+ map.set(s[end], end);
13
+ maxLen = Math.max(maxLen, end - start + 1);
14
15
+ return maxLen;
16
+};
17
18
+// TC: O(n)
19
+// SC: O(n)
0 commit comments