Deep_Lee
article thumbnail


replace ํ˜น์€ replaceAll ๋ฉ”์†Œ๋“œ๋ฅผ ์ด์šฉํ•œ๋‹ค.

 

๋ฐฐ์—ด num๊ณผ for๋ฌธ์˜ i index๊ฐ€ ์ผ์น˜ํ•˜๋ฏ€๋กœ, ์˜๋ฌธ์ž๋ฅผ ๋ชจ๋‘ ๋ฌธ์ž์—ด ์ˆซ์ž๋กœ ๋ณ€๊ฒฝํ•˜๊ณ 

๋งˆ์ง€๋ง‰์— ์ˆซ์ž ๋ฌธ์ž์—ด s๋ฅผ Integer.parseInt ๋กœ ์ •์ˆ˜ํ™”์‹œํ‚จ๋‹ค.

 

 

class Solution {
    public int solution(String s) {
    	int answer = 0;

        String[] num ={"zero","one","two","three","four","five","six","seven","eight","nine"};
        for(int i=0; i<10; i++){
            s=s.replace(num[i],Integer.toString(i));
        }
        answer = Integer.parseInt(s);
        return answer;
    }
}