프로그래머스 - 숫자 문자열과 영단어

parkkhee·2023년 4월 14일
0

Level1

목록 보기
18/23
class Solution {
    public int solution(String s) {
        int answer = 0;
        String[] alp = {"one", "two", "zero", "three", "four", "five", "six", "seven",
                      "eight" , "nine"};
        int[] num = {1,2,0,3,4,5,6,7,8,9};
        
        for(int i=0; i<10; i++){
            if(s.contains(alp[i])){
                s = s.replace(alp[i], ""+num[i]);
            }
            
        }
        answer = Integer.parseInt(s);
        
        
        return answer;
    }
}
profile
순우리말 백엔드 개발자

0개의 댓글