Lv2. 124 나라의 숫자 Javascript
https://programmers.co.kr/learn/courses/30/lessons/12899?language=javascript
function solution(n) {
let answer = "";
while (n > 0) {
switch (n % 3) {
case 1:
answer = 1 + answer;
n = Math.floor(n / 3);
break;
case 2:
answer = 2 + answer;
n = Math.floor(n / 3);
break;
case 0:
answer = 4 + answer;
n = n / 3 - 1;
break;
}
}
return answer;
}
패턴을 찾기 까다로웠던 문제.
댓글 환영
질문 환영
by.protect-me