JuniorMath
Mirror Distance of an Integer
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.
Example 1
Input
n = 25Output
27reverse(25) = 52, so the answer is abs(25 - 52) = 27.Example 2
Input
n = 10Output
9reverse(10) = 01, which is 1, so the answer is abs(10 - 1) = 9.Constraints
- 1 <= n <= 10^9