Skip to content

Commit 72b9c90

Browse files
committed
feat: solve 4
1 parent d459373 commit 72b9c90

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed
Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,25 @@
1+
"""
2+
Blind75 - length of longest substring without repeating characters
3+
https://leetcode.com/problems/longest-substring-without-repeating-characters/
4+
์‹œ๊ฐ„๋ณต์žก๋„ : O(n)
5+
๊ณต๊ฐ„๋ณต์žก๋„ : O(min(m, n)) (๋ฌธ์ž ์ง‘ํ•ฉ char_index_map์˜ ํฌ๊ธฐ, ์ตœ๋Œ€๋Š” n = len(s))
6+
ํ’€์ด : ์Šฌ๋ผ์ด๋”ฉ ์œˆ๋„์šฐ ๊ธฐ๋ฒ•์„ ์‚ฌ์šฉํ•œ ๋ฌธ์ž์—ด ์ˆœํšŒ
7+
"""
8+
9+
110
class Solution:
211
def lengthOfLongestSubstring(self, s: str) -> int:
3-
12+
max_count = 0
13+
start = 0
14+
char_index_map = {}
15+
16+
for i, char in enumerate(s):
17+
if char in char_index_map and char_index_map[char] >= start:
18+
start = char_index_map[char] + 1
19+
char_index_map[char] = i
20+
else:
21+
char_index_map[char] = i
22+
max_count = max(max_count, i - start + 1)
423

24+
return max_count
25+

0 commit comments

Comments
ย (0)