[프로그래머스] Lv.1 숫자 문자열과 영단어.java

hgghfgf·2023년 7월 1일
0

프로그래머스

목록 보기
200/227

숫자 문자열과 영단어.java

class Solution {
    public int solution(String s) {
        String[] num = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};
        String[] word = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};

        for(int i = 0; i < 10; i++){
            s = s.replace(word[i], num[i]);
        }

        return Integer.parseInt(s);
    }
}

출처: 프로그래머스 코딩 테스트 연습, https://school.programmers.co.kr/learn/courses/30/lessons/81301

0개의 댓글