1432. Max Difference You Can Get From Changing an Integer Medium
1/**
2 * [1432] Max Difference You Can Get From Changing an Integer
3 *
4 * You are given an integer num. You will apply the following steps exactly two times:
5 *
6 * Pick a digit x (0 <= x <= 9).
7 * Pick another digit y (0 <= y <= 9). The digit y can be equal to x.
8 * Replace all the occurrences of x in the decimal representation of num by y.
9 * The new integer cannot have any leading zeros, also the new integer cannot be 0.
10 *
11 * Let a and b be the results of applying the operations to num the first and second times, respectively.
12 * Return the max difference between a and b.
13 *
14 * Example 1:
15 *
16 * Input: num = 555
17 * Output: 888
18 * Explanation: The first time pick x = 5 and y = 9 and store the new integer in a.
19 * The second time pick x = 5 and y = 1 and store the new integer in b.
20 * We have now a = 999 and b = 111 and max difference = 888
21 *
22 * Example 2:
23 *
24 * Input: num = 9
25 * Output: 8
26 * Explanation: The first time pick x = 9 and y = 9 and store the new integer in a.
27 * The second time pick x = 9 and y = 1 and store the new integer in b.
28 * We have now a = 9 and b = 1 and max difference = 8
29 *
30 *
31 * Constraints:
32 *
33 * 1 <= num <= 10^8
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/max-difference-you-can-get-from-changing-an-integer/
39// discuss: https://leetcode.com/problems/max-difference-you-can-get-from-changing-an-integer/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn max_diff(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_1432() {
57 }
58}
59
Back
© 2025 bowen.ge All Rights Reserved.