Beakjoon&프로그래머스/Java

[프로그래머스/Java] 숫자 문자열과 영단어

현장 2025. 2. 25. 21:09

-Code

import java.util.List;

class Solution {
    public int solution(String s) {
        List<String> numStrings = List.of(
                "zero", "one", "two", "three", "four",
                "five", "six", "seven", "eight", "nine"
        );

        for (int i = 0; i < 10; i++) {
            String now = numStrings.get(i);
            if (s.contains(now)) {
                System.out.println(now);
                s = s.replaceAll(now, String.valueOf(i));
            }
        }

        return Integer.parseInt(s);
    }
}