Show problems as
Classic problem #3783EasyMath

Mirror Distance of an Integer

Real-world version: Gap to the Mirrored Number
Tracked in this browser only
Read Mirror Distance of an Integer on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

Reading the digits of n in the opposite order gives another whole number, dropping any leading zeros that appear.

Return how far apart the two numbers are.

Examples

Example 1

Input
n = 4213
Output
1089

Reading the digits the other way gives 3124, and 4213 less 3124 is 1089.

Example 2

Input
n = 200
Output
198

The digits read backwards give 002, which is the number 2, so the gap is 198.

Example 3

Input
n = 1221
Output
0

The number reads the same either way, so the gap is nothing.

Constraints

  • 1 <= n <= 10^9

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def mirror_distance(n: int) -> int:
Java
public int mirrorDistance(int n)