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 9612086 commit c65779bCopy full SHA for c65779b
โlongest-substring-without-repeating-characters/Tessa1217.java
@@ -0,0 +1,29 @@
1
+/**
2
+ * ๋ฌธ์์ด s๊ฐ ์ฃผ์ด์ง ๋ ์ค๋ณต ๋ฌธ์๊ฐ ์๋ ๊ฐ์ฅ ๊ธด ๋ฌธ์์ด ๊ธธ์ด๋ฅผ ๋ฐํํ์ธ์.
3
+ * */
4
+class Solution {
5
+ // ์๊ฐ๋ณต์ก๋: O(n)
6
+ public int lengthOfLongestSubstring(String s) {
7
+
8
+ int maxLength = 0;
9
10
+ int left = 0;
11
+ int right = 0;
12
13
+ // ์ํ๋ฒณ (๋์๋ฌธ์), ์ซ์, ํน์๋ฌธ์, ๊ณต๋ฐฑ
14
+ boolean[] visited = new boolean[128];
15
16
+ while (right < s.length()) {
17
+ while (visited[s.charAt(right)]) {
18
+ visited[s.charAt(left)] = false;
19
+ left++;
20
+ }
21
+ visited[s.charAt(right)] = true;
22
+ maxLength = Math.max(right - left + 1, maxLength);
23
+ right++;
24
25
26
+ return maxLength;
27
28
+}
29
0 commit comments