Skip to content

Commit 344e9d5

Browse files
committed
solve 2
1 parent 7f74c8c commit 344e9d5

File tree

1 file changed

+23
-0
lines changed
  • longest-substring-without-repeating-characters

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'''
2+
시간복잡도: O(n)
3+
- right와 left 포인터가 각각 최대 n번 움직임
4+
5+
공간복잡도: O(n)
6+
- hars 집합이 최대 n개의 고유 문자를 저장할 수 있
7+
'''
8+
9+
class Solution:
10+
def lengthOfLongestSubstring(self, s: str) -> int:
11+
length = 0
12+
left = 0
13+
chars = set()
14+
15+
for right in range(len(s)):
16+
if s[right] in chars:
17+
while s[right] in chars:
18+
chars.remove(s[left])
19+
left += 1
20+
chars.add(s[right])
21+
length = max(length, right + 1 - left)
22+
23+
return length

0 commit comments

Comments
 (0)