코테/프로그래머스

[프로그래머스/Lv. 0] 영어가 싫어요

imname1am 2023. 1. 31. 16:43
반응형
class Solution {
    public long solution(String numbers) {

        numbers = numbers.replaceAll("zero", "0")
                         .replaceAll("one", "1")
                         .replaceAll("two", "2")
                         .replaceAll("three", "3")
                         .replaceAll("four", "4")
                         .replaceAll("five", "5")
                         .replaceAll("six", "6")
                         .replaceAll("seven", "7")
                         .replaceAll("eight", "8")
                         .replaceAll("nine", "9");
      
        return Integer.parseInt(numbers);
    }
}

처음에는 return Integer.parseInt(numbers); 이렇게 했는데 테스트 1,3,9에서 런타임 에러가 났다...

 

그래서 질문하기란을 봤다...🤔

 

프로그래머스

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

programmers.co.kr

‼‼‼ 힌트에 이마를 탁 치고 저렇게 바꿔봤더니 잘 맞았다🤸‍♀️

class Solution {
    public long solution(String numbers) {

        numbers = numbers.replaceAll("zero", "0")
                         .replaceAll("one", "1")
                         .replaceAll("two", "2")
                         .replaceAll("three", "3")
                         .replaceAll("four", "4")
                         .replaceAll("five", "5")
                         .replaceAll("six", "6")
                         .replaceAll("seven", "7")
                         .replaceAll("eight", "8")
                         .replaceAll("nine", "9");
        
        return Long.parseLong(numbers);
    }
}

(TMI) 사실 나는 영어를 좋아한다...🙃

반응형