반응형
🔺 문제
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
🔺 코드
import java.util.*;
class Solution {
public int solution(String s) {
int answer = 0;
s = s.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(s);
}
}
일일이 replaceAll 해주었다,,^^
🔺 다른 풀이들
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
class Solution {
public int solution(String s) {
String[] strArr = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
for(int i = 0; i < strArr.length; i++) {
s = s.replaceAll(strArr[i], Integer.toString(i));
}
return Integer.parseInt(s);
}
}
깔끔하구나-!
반응형
'코테 > 프로그래머스' 카테고리의 다른 글
[프로그래머스/Lv. 1] 두 개 뽑아서 더하기 (0) | 2023.03.06 |
---|---|
[프로그래머스/Lv. 1] 문자열 내 마음대로 정렬하기 (0) | 2023.03.06 |
[프로그래머스/Level1] 이상한 문자 만들기 (0) | 2023.03.04 |
[프로그래머스/Lv. 1] 문자열 다루기 기본 (0) | 2023.03.03 |
[프로그래머스/Lv. 1] 없는 숫자 더하기 (0) | 2023.03.03 |