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 4c1d721 commit 054c2d9Copy full SHA for 054c2d9
โlongest-substring-without-repeating-characters/uraflower.jsโ
@@ -0,0 +1,28 @@
1
+/**
2
+ * ๋ฌธ์์ด์์ ์ค๋ณต ๋ฌธ์ ์๋ ๊ฐ์ฅ ๊ธด ๋ถ๋ถ ๋ฌธ์์ด์ ๊ธธ์ด๋ฅผ ๋ฐํํ๋ ํจ์
3
+ * @param {string} s
4
+ * @return {number}
5
+ */
6
+const lengthOfLongestSubstring = function(s) {
7
+ let start = 0;
8
+ let end = 0;
9
+
10
+ const set = new Set();
11
+ let maxSize = 0;
12
13
+ while (end < s.length) {
14
+ while (set.has(s[end])) {
15
+ set.delete(s[start]);
16
+ start++;
17
+ }
18
19
+ set.add(s[end]);
20
+ maxSize = Math.max(maxSize, set.size);
21
+ end++;
22
23
24
+ return maxSize;
25
+};
26
27
+// ์๊ฐ๋ณต์ก๋: O(n) (์ต๋ end๋ก n๋ฒ, start๋ก n๋ฒ ์ด๋ํ๋ฏ๋ก 2n๋งํผ ์์)
28
+// ๊ณต๊ฐ๋ณต์ก๋: O(n)
0 commit comments