ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [프로그래머스/javascript] 124나라의 숫자 (다시 풀기)
    카테고리 없음 2023. 3. 20. 11:49
    function solution(n) {
        const answer = [];
        //3진수라고 생각할것. 계속 나누고,
        //나머지는 answer에 추가하고 몫은 계속 가지고 있는다.
        let quotient = n;
        while(quotient>0){
            let reminder = quotient%3;
            quotient = Math.floor(quotient/3);
            if(reminder===0) {answer.push(4)
                             quotient--}
            else answer.push(reminder)
        }
        
        return answer.reverse().join('')
    }

     

Designed by Tistory.