3783. Mirror Distance of an Integer Easy
1/**
2 * [3783] Mirror Distance of an Integer
3 *
4 * You are given an integer n.
5 * Define its mirror distance as: abs(n - reverse(n)) where reverse(n) is the integer formed by reversing the digits of n.
6 * Return an integer denoting the mirror distance of n.
7 * abs(x) denotes the absolute value of x.
8 *
9 * <strong class="example">Example 1:
10 * <div class="example-block">
11 * Input: <span class="example-io">n = 25</span>
12 * Output: <span class="example-io">27</span>
13 * Explanation:
14 *
15 * reverse(25) = 52.
16 * Thus, the answer is abs(25 - 52) = 27.
17 * </div>
18 * <strong class="example">Example 2:
19 * <div class="example-block">
20 * Input: <span class="example-io">n = 10</span>
21 * Output: <span class="example-io">9</span>
22 * Explanation:
23 *
24 * reverse(10) = 01 which is 1.
25 * Thus, the answer is abs(10 - 1) = 9.
26 * </div>
27 * <strong class="example">Example 3:
28 * <div class="example-block">
29 * Input: <span class="example-io">n = 7</span>
30 * Output: <span class="example-io">0</span>
31 * Explanation:
32 *
33 * reverse(7) = 7.
34 * Thus, the answer is abs(7 - 7) = 0.
35 * </div>
36 *
37 * Constraints:
38 *
39 * 1 <= n <= 10^9
40 *
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/mirror-distance-of-an-integer/
45// discuss: https://leetcode.com/problems/mirror-distance-of-an-integer/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50 pub fn mirror_distance(n: i32) -> i32 {
51 0
52 }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn test_3783() {
63 }
64}
65Back
© 2026 bowen.ge All Rights Reserved.