2566. Maximum Difference by Remapping a Digit Easy
1/**
2 * [2566] Maximum Difference by Remapping a Digit
3 *
4 * You are given an integer num. You know that Bob will sneakily remap one of the 10 possible digits (0 to 9) to another digit.
5 * Return the difference between the maximum and minimum values Bob can make by remapping exactly one digit in num.
6 * Notes:
7 *
8 * When Bob remaps a digit <font face="monospace">d1</font> to another digit <font face="monospace">d2</font>, Bob replaces all occurrences of d1 in num with d2.
9 * Bob can remap a digit to itself, in which case num does not change.
10 * Bob can remap different digits for obtaining minimum and maximum values respectively.
11 * The resulting number after remapping can contain leading zeroes.
12 *
13 *
14 * Example 1:
15 *
16 * Input: num = 11891
17 * Output: 99009
18 * Explanation:
19 * To achieve the maximum value, Bob can remap the digit 1 to the digit 9 to yield 99899.
20 * To achieve the minimum value, Bob can remap the digit 1 to the digit 0, yielding 890.
21 * The difference between these two numbers is 99009.
22 *
23 * Example 2:
24 *
25 * Input: num = 90
26 * Output: 99
27 * Explanation:
28 * The maximum value that can be returned by the function is 99 (if 0 is replaced by 9) and the minimum value that can be returned by the function is 0 (if 9 is replaced by 0).
29 * Thus, we return 99.
30 *
31 * Constraints:
32 *
33 * 1 <= num <= 10^8
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/maximum-difference-by-remapping-a-digit/
39// discuss: https://leetcode.com/problems/maximum-difference-by-remapping-a-digit/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn min_max_difference(num: i32) -> i32 {
45 0
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_2566() {
57 }
58}
59
Back
© 2025 bowen.ge All Rights Reserved.