Skip to content

Commit e0e3d6b

Browse files
committed
2165. Smallest Value of the Rearranged Number: RETRY
1 parent 0824359 commit e0e3d6b

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

src/solution/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,3 +1636,4 @@ mod s2161_partition_array_according_to_given_pivot;
16361636
mod s2162_minimum_cost_to_set_cooking_time;
16371637
mod s2163_minimum_difference_in_sums_after_removal_of_elements;
16381638
mod s2164_sort_even_and_odd_indices_independently;
1639+
mod s2165_smallest_value_of_the_rearranged_number;
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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+
*/
28+
pub 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+
35+
impl Solution {
36+
pub fn smallest_number(num: i64) -> i64 {
37+
0
38+
}
39+
}
40+
41+
// submission codes end
42+
43+
#[cfg(test)]
44+
mod tests {
45+
use super::*;
46+
47+
#[test]
48+
#[ignore]
49+
fn test_2165_example_1() {
50+
let num = 310;
51+
52+
let result = 103;
53+
54+
assert_eq!(Solution::smallest_number(num), result);
55+
}
56+
57+
#[test]
58+
#[ignore]
59+
fn test_2165_example_2() {
60+
let num = -7605;
61+
62+
let result = -7650;
63+
64+
assert_eq!(Solution::smallest_number(num), result);
65+
}
66+
}

0 commit comments

Comments
 (0)