코딩테스트

[힌트 문제1-2]숫자 문자열과 영단어

개발하는지호 2023. 9. 19. 16:45

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]);
            
        }
        int a = Integer.parseInt(s);
        return a;
        
    }
    
    
}