[문자열] 숫자 영단어와 문자열

조은지·2021년 10월 23일
0

코드

class Solution {
    public String[] nums = {"0","1","2","3","4","5","6","7","8","9"};
    public String[] words = {"zero","one","two","three","four","five","six","seven","eight","nine"};
    public int solution(String s) {
        String tmp = "";
        int answer = 0;
        for(int i=0;i<words.length;i++){
            s = s.replace(words[i],nums[i]);
        }
        answer = Integer.parseInt(s);
        return answer;
    }
}

어제 문자열은 안한거 같아서 한 문제 풀어봤다.

0개의 댓글