Skip to content

Commit a1828aa

Browse files
committed
feat: Solve longest-substring-without-repeating-characters problem
1 parent a82617b commit a1828aa

File tree

1 file changed

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

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
"""
3+
a => ์„ธํŠธ {}์— a ์—†์Œ
4+
ab => ์„ธํŠธ {a}์— b ์—†์Œ
5+
aba => ์„ธํŠธ {a, b}์— a ์žˆ์Œ => ์ค‘๋ณต
6+
abac => ๋” ์ด์ƒ ๊ณ ๋ ค ๊ฐ€์น˜ ์—†์Œ
7+
"""
8+
def lengthOfLongestSubstring(self, s: str) -> int:
9+
max_len = 0
10+
for start in range(len(s)):
11+
chars = set()
12+
for end in range(start, len(s)):
13+
if s[end] in chars:
14+
break
15+
chars.add(s[end])
16+
max_len = max(end - start + 1, max_len)
17+
return max_len

0 commit comments

Comments
ย (0)