본문 바로가기
프로그래밍 문제/[Python] CheckIO

[CheckIO/Scientific Expedition] Longest substring of unique characters

by UltraLowTemp-Physics 2024. 2. 18.

1. Problem : https://py.checkio.org/en/mission/longest-substring-of-unique-characters/
2. My solution

python
접기
def longest_substr(s: str) -> int:
# your code here
no_repeat_list = []
longest = 0
for char in [*s]:
if no_repeat_list.count(char) == 0: no_repeat_list.append(char)
else:
index = no_repeat_list.index(char)+1
no_repeat_list.append(char)
no_repeat_list = no_repeat_list[index:]
if len(no_repeat_list) > longest: longest = len(no_repeat_list)
return longest

 

댓글