ALGORITHM
[JAVA] 프로그래머스 - 숫자 문자열과 영단어
연듀
2022. 12. 19. 15:23
https://school.programmers.co.kr/learn/courses/30/lessons/81301
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
class Solution {
public int solution(String s) {
String[] nums = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
for(int i=0; i<nums.length; i++){
s = s.replaceAll(nums[i], Integer.toString(i));
}
return Integer.parseInt(s);
}
}
숫자 문자열을 만들어 차례로 돌면서 해당 인덱스의 문자열을 해당 인덱스 숫자로 바꿔준다.
반응형