seunghyun Note
[프로그래머스] - 숫자 문자열과 영단어 with JAVA 본문
링크 : https://school.programmers.co.kr/learn/courses/30/lessons/81301
문제 풀이
class Solution {
public int solution(String s) {
// 0~9 index 문자열 배열에 저장
String[] str = {"zero","one","two","three","four","five","six","seven","eight","nine"};
//각 요소마다 문자열에 속하면 바꿔주기
//"zero2" -> "02"
for(int i=0;i<str.length;i++){
if(s.contains(str[i])) {
s = s.replace(str[i],Integer.toString(i));
}
}
//정수형으로 변경
return Integer.parseInt(s);
}
}
728x90
'코딩테스트 > 백준' 카테고리의 다른 글
[프로그래머스] - 부분 문자열인지 확인하기 with JAVA (0) | 2024.01.06 |
---|---|
[프로그래머스] - 예산 with JAVA (1) | 2024.01.06 |
[프로그래머스] - 가장 가까운 같은 글자 with JAVA (0) | 2024.01.06 |
[프로그래머스] - 문자열 내 마음대로 정렬하기 With JAVA (0) | 2024.01.06 |
[프로그래머스] - 카드 뭉치 with JAVA (0) | 2024.01.06 |