Skip to content

Commit fbffd5e

Browse files
committed
longest-substring-without-repeating-characters solution
1 parent bba4367 commit fbffd5e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution:
2+
def lengthOfLongestSubstring(self, s: str) -> int:
3+
4+
# 브루트포스(시간복잡도 : O(n^2))
5+
answer = 0
6+
7+
for i in range(len(s)):
8+
# 중복없는 문자열을 저장할 집합
9+
substring = set()
10+
11+
for j in range(i,len(s)):
12+
13+
# 중복 문자를 만나면 break
14+
if s[j] in substring:
15+
break
16+
17+
# 중복 아니면 문자 추가하고 긴 문자열 길이 비교해서 업데이트
18+
substring.add(s[j])
19+
answer = max(answer, len(substring))
20+
21+
return answer

0 commit comments

Comments
 (0)