Ad
Code
Diff
  • import java.util.Arrays;
    
    public class MaxNumber {
        public static long print(long number) {
            
            long num = Math.abs(number);
            
            int[] digitCount = new int[10];
            
            while (num > 0) {
                digitCount[(int)(num % 10)]++;
                num /= 10;
            }
            
            long maxNumber = 0;
            for (int i = 9; i >= 0; i--) {
                for (int j = 0; j < digitCount[i]; j++) {
                    maxNumber = maxNumber * 10 + i;
                }
            }
            
            if (number < 0) {
                return -maxNumber;
            }
            
            return maxNumber;
        }
    }
    
    • import java.util.Arrays;
    • public class MaxNumber {
    • public static long print(long number) {
    • return number
    • long num = Math.abs(number);
    • int[] digitCount = new int[10];
    • while (num > 0) {
    • digitCount[(int)(num % 10)]++;
    • num /= 10;
    • }
    • long maxNumber = 0;
    • for (int i = 9; i >= 0; i--) {
    • for (int j = 0; j < digitCount[i]; j++) {
    • maxNumber = maxNumber * 10 + i;
    • }
    • }
    • if (number < 0) {
    • return -maxNumber;
    • }
    • return maxNumber;
    • }