seunghyun Note

[프로그래머스] - 숫자 문자열과 영단어 with JAVA 본문

코딩테스트/백준

[프로그래머스] - 숫자 문자열과 영단어 with JAVA

승숭슝현 2024. 1. 6. 22:21

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

 

프로그래머스

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

programmers.co.kr

 

2021 카카오 채용연계형 인턴십

문제 풀이

class Solution {
    public int solution(String s) {
    
    // 0~9 index 문자열 배열에 저장
        String[] str = {"zero","one","two","three","four","five","six","seven","eight","nine"};
        
        //각 요소마다 문자열에 속하면 바꿔주기 
        //"zero2" -> "02"
        for(int i=0;i<str.length;i++){
            if(s.contains(str[i])) {
                s =  s.replace(str[i],Integer.toString(i));
            }
        }
        //정수형으로 변경
        return Integer.parseInt(s);
    }
}
728x90