[LeetCode] Mirror Distance of an Integer

3783. 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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class Solution {
long long rev(int n) {
long long res = 0;
while(n) {
res = res * 10 + (n % 10);
n /= 10;
}
return res;
}
public:
int mirrorDistance(int n) {
return abs(n - rev(n));
}
};
Author: Song Hayoung
Link: https://songhayoung.github.io/2026/09/04/PS/LeetCode/mirror-distance-of-an-integer/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.