Coding Test/JAVA 코딩테스트 풀이정리(프로그래머스)

프로그래머스 스쿨 Lv.1 - 숫자 문자열과 영단어(replace 활용)
깝몬 2024. 1. 2. 18:27

문제

https://school.programmers.co.kr/learn/courses/30/lessons/81301

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

정답

 

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

 

시간복잡도에 특별한 의미가 있나했지만 그렇진 않았다.