728x90
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
📌 정리
파이썬에서 replace
- replace(old, new, [count]) ➡️ old는 찾을 값, new는 바꿀 값, count는 바꿀 횟수
s = s.replace(number[i][1], number[i][0], 99)
- 자바에서는 replace와 replaceAll 2개로 나눠져 있는데, 파이썬은 replace 하나밖에 없다.
📌 전체 코드
def solution(s):
number = [["0", "zero"],["1", "one"],["2", "two"],["3", "three"],["4", "four"],["5", "five"],["6", "six"],["7", "seven"],["8", "eight"],["9", "nine"]]
for i in range(len(number)):
s = s.replace(number[i][1], number[i][0], 99)
answer = int(s)
return answer
728x90
'코테 > Algorithm' 카테고리의 다른 글
[프로그래머스] Lv.2 호텔 대실 (JAVA) (1) | 2025.05.12 |
---|---|
[프로그래머스] [1차] 비밀지도 (Python/JAVA) (1) | 2025.04.15 |
[프로그래머스] 서울에서 김서방 찾기 (Python) (0) | 2025.04.14 |
[프로그래머스] 없는 숫자 더하기(Python) (0) | 2025.04.14 |
[BOJ] 1991: 트리순회 (JAVA) (0) | 2025.02.25 |