Given an integer, sort the digits in ascending order and return the new integer
Anonymous User
5222

I stucked in the below question, specially they specify not using any data structure or convertion way.
/**

  • Given an integer, sort the digits in ascending order and return the new integer.
  • Ignore leading zeros.
  • Parameters
  • Input: num {Integer}
  • Output: {Integer}
  • Constraints
  • Do not convert the integer into a string or other data type.
  • Time: O(N) where N is the number of digits.
  • Space: O(1)
  • Examples
  • 8970 --> 789
  • 32445 --> 23445
  • 10101 --> 111
    */
   public static int sortDigits(int n) {
     
    return -1;
   }
Comments (3)