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 fe403cd commit c632276Copy full SHA for c632276
1 file changed
longest-substring-without-repeating-characters/hyejj19.ts
@@ -0,0 +1,24 @@
1
+function lengthOfLongestSubstring(s: string): number {
2
+ if (s.length <= 1) return s.length;
3
+
4
+ let left = 0;
5
+ let right = 0;
6
+ let maxLen = -1;
7
+ const sMap = new Map();
8
+ while (right !== s.length) {
9
+ const curS = s[right];
10
+ // Map에 존재하지 않는다 -> 중복 X -> right 전진
11
+ if (!sMap.get(curS)) {
12
+ sMap.set(s[right], 1);
13
+ right++;
14
+ } else {
15
+ // Map에 존재 한다 -> 중복 O -> left 전진
16
+ while (left <= right && sMap.get(curS)) {
17
+ sMap.set(s[left], sMap.get(s[left]) - 1);
18
+ left++;
19
+ }
20
21
+ maxLen = Math.max(maxLen, right - left);
22
23
+ return maxLen;
24
+}
0 commit comments