공부블로그
[프로그래머스] 숫자 문자열과 영단어 본문
https://school.programmers.co.kr/learn/courses/30/lessons/81301
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
class Solution {
public int solution(String s) {
StringBuilder sb= new StringBuilder(s);
String[] str =
{"zero","one","two", "three","four","five","six","seven","eight", "nine"};
for(int i=0; i<10; i++){
while(true){
int start = sb.toString().indexOf(str[i]);
if(start<0) break; //검색 실패
sb.replace(start, start+str[i].length(), i+"");
}
}
int answer = Integer.valueOf(sb.toString());
return answer;
}
}
'IT > 알고리즘' 카테고리의 다른 글
[프로그래머스] 예산 (0) | 2022.07.18 |
---|---|
[프로그래머스] 신규 아이디 추천 (0) | 2022.07.15 |
[프로그래머스] 1차 비밀지도 (0) | 2022.07.07 |
[프로그래머스] 신고결과 받기 (0) | 2022.06.18 |
[프로그래머스] 로또의 최고 순위와 최저 순위 (0) | 2022.06.15 |
Comments