728x90
Programmers
글자 지우기
https://school.programmers.co.kr/learn/courses/30/lessons/181900
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
문제
코드
<풀이1>
- enumerate 사용하여 indices에 없다면 answer에 넣어주는 방식
def solution(my_string, indices):
answer = ''
for idx, val in enumerate(my_string):
if idx not in indices:
answer += val
return answer
<풀이2>
- del을 사용해 삭제하는 방식
def solution(my_string, indices):
my_string = list(my_string)
for i in sorted(indices, reverse=True):
del my_string[i]
return ''.join(my_string)
<풀이3>
def solution(my_string, indices):
answer = ''
for i in range(len(my_string)):
if i not in indices:answer+=my_string[i]
return answer
Reference
728x90
반응형
'Algorithm > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 가까운 1 찾기 - 파이썬 (0) | 2024.03.20 |
---|---|
[프로그래머스] 카운트 다운 - 파이썬 (0) | 2024.03.20 |
[프로그래머스] 배열 만들기 1 - 파이썬 (0) | 2024.03.20 |
[프로그래머스] qr code - 파이썬 (0) | 2024.03.19 |
[프로그래머스] 세로 읽기 - 파이썬 (0) | 2024.03.19 |