본문 바로가기
알고리즘/프로그래머스 2단계

[프로그래머스] 124 나라의 숫자

by lanuarius19 2022. 6. 5.
728x90

프로그래머스 2단계
124 나라의 숫자

https://programmers.co.kr/learn/challenges

 

문제 설명

 

124 나라의 숫자

 

 

 

풀이

 

class Solution {
    public String solution(int n) {
        StringBuilder sb = new StringBuilder();
        int count = 1;
        
        while (n>0){
            count = n % 3;
            n = n / 3;
            
            if(count == 0){
                n = n - 1;
                count = 4;
            }
            
            sb.insert(0, count);
        }
        return sb.toString();
    }
}
 
728x90

댓글