happy coding
[level 0] 중복된 문자 제거 본문
문제 설명
문자열 my_string이 매개변수로 주어집니다. my_string에서 중복된 문자를 제거하고 하나의 문자만 남긴 문자열을 return하도록 solution 함수를 완성해주세요.
제한사항
- 1 ≤ my_string ≤ 110
- my_string은 대문자, 소문자, 공백으로 구성되어 있습니다.
- 대문자와 소문자를 구분합니다.
- 공백(" ")도 하나의 문자로 구분합니다.
- 중복된 문자 중 가장 앞에 있는 문자를 남깁니다.
def solution(my_string):
ans = ''.join(dict.fromkeys(my_string))
return ans
다른 사람 풀이
def solution(my_string):
answer = ''
for i in my_string:
if i not in answer:
answer+=i
return answer
'coding study > programmars' 카테고리의 다른 글
[level 0] 합성수 찾기 (0) | 2024.06.01 |
---|---|
[level 0] 주사위의 개수 (0) | 2024.06.01 |
[level 0] k의 개수 (0) | 2024.06.01 |
[level 0] 369게임 (0) | 2024.05.29 |
[level 0] 문자열 정렬하기(2) (0) | 2024.05.29 |
Comments