코딩테스트/Programmers

[Programmers] 숫자 문자열과 영단어

주니어주니 2023. 8. 30. 12:48

 

 

 

아 미쳤다 

substring으로 잘라서 for문 돌려가면서 난리부르스를 춰도 안되길래 너무 어렵다 생각했는데

이렇게 간단한 문제였다니 ㅠ

replace !!!! 바보

class Solution {
    public int solution(String s) {
        String[] word = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}; 
        
        for(int i=0; i<word.length; i++) {
            s = s.replaceAll(word[i], Integer.toString(i));
        }

        return Integer.parseInt(s);
        
    }
}