[프로그래머스] 코딩테스트 연습 - 연습문제 Level 1 정수 내림차순으로 배치하기

uoahy·2021년 9월 27일
0

Solution.java

class Solution {
    public long solution(long n) {
        long answer = 0;
        
        int[] count = new int[10];
        while (n != 0) {
            count[(int) (n % 10)]++;
            n /= 10;
        }
        
        for (int i = 9; i >= 0; i--) {
            for (int j = 0; j < count[i]; j++) {
                answer *= 10;
                answer += i;
            }
        }
        
        return answer;
    }
}

출처: 프로그래머스 코딩 테스트 연습, https://programmers.co.kr/learn/challenges

0개의 댓글