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)