2165. Smallest Value of the Rearranged Number Medium
1/**
2 * [2165] Smallest Value of the Rearranged Number
3 *
4 * You are given an integer num. Rearrange the digits of num such that its value is minimized and it does not contain any leading zeros.
5 * Return the rearranged number with minimal value.
6 * Note that the sign of the number does not change after rearranging the digits.
7 *
8 * Example 1:
9 *
10 * Input: num = 310
11 * Output: 103
12 * Explanation: The possible arrangements for the digits of 310 are 013, 031, 103, 130, 301, 310.
13 * The arrangement with the smallest value that does not contain any leading zeros is 103.
14 *
15 * Example 2:
16 *
17 * Input: num = -7605
18 * Output: -7650
19 * Explanation: Some possible arrangements for the digits of -7605 are -7650, -6705, -5076, -0567.
20 * The arrangement with the smallest value that does not contain any leading zeros is -7650.
21 *
22 *
23 * Constraints:
24 *
25 * -10^15 <= num <= 10^15
26 *
27 */
28pub struct Solution {}
29
30// problem: https://leetcode.com/problems/smallest-value-of-the-rearranged-number/
31// discuss: https://leetcode.com/problems/smallest-value-of-the-rearranged-number/discuss/?currentPage=1&orderBy=most_votes&query=
32
33// submission codes start here
34
35impl Solution {
36 pub fn smallest_number(num: i64) -> i64 {
37
38 }
39}
40
41// submission codes end
42
43#[cfg(test)]
44mod tests {
45 use super::*;
46
47 #[test]
48 fn test_2165() {
49 }
50}
51
Back
© 2025 bowen.ge All Rights Reserved.