Skip to main content
Back to problems
#3783
Easy Algorithms

Mirror distance of an integer

Math
87.5% acceptance
Feb 25, 2026
54
2
You are given an integer n. Define its mirror distance as: abs(n - reverse(n))​​​​​​​ where reverse(n) is the integer formed by reversing the digits of n. Return an integer denoting the mirror distance of n​​​​​​​. abs(x) denotes the absolute value of x.

Solution

Rust
Time O(1)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn mirror_distance(n: i32) -> i32 {
    let rev: i32 = n.to_string().chars().rev().collect::<String>().parse().unwrap();
    (n - rev).abs()
  }
}