프로그래머스

숫자 문자열과 영단어

끝까지 처음처럼 2022. 9. 9. 20:11
728x90
class Solution {
    fun solution(s: String): Int {
        // one4seveneight
        val spel = listOf("zero","one","two","three","four","five","six","seven","eight","nine")

        var temp = s

        for(i in 0 .. spel.size-1){
            if(temp.contains(spel[i])){
                temp = temp.replace(spel[i],i.toString())
            }
        }

        return temp.toInt()
    }
}

저의 현재 실력으로 푼 문제 답안이며, 가장 좋은 코드는 아닐 수 있으며, 코틀린을 공부하면서 추가적으로 알게 된 개념이 있어 다시 풀 경우 추가적으로 코드를 작성 할 수 있도록 하겠습니다.