#2165
Smallest Value of the Rearranged Number
specialist · 820 · lc medium +31 · verified · 53.4% accepted · 683 likes · top 44%
Description
You are given an integer num. Rearrange its digits to produce the smallest possible value without leading zeros.
The sign of the number is preserved after rearranging.
Return the rearranged number with the minimal value.
Example 1:
Input: num = 310
Output: 103
Explanation: The possible arrangements for the digits of 310 are 013, 031, 103, 130, 301, 310.
The arrangement with the smallest value that does not contain any leading zeros is 103.
Example 2:
Input: num = -7605
Output: -7650
Explanation: Some possible arrangements for the digits of -7605 are -7650, -6705, -5076, -0567.
The arrangement with the smallest value that does not contain any leading zeros is -7650.
Code
1
2
3