Back to April Back to Year 2026
EASY 18 Apr 2026 View on LeetCode

3783. Mirror Distance of an Integer

</> Solution

/**
 * Problem: LeetCode 3783 - Mirror Distance of an Integer
 * Difficulty: Easy
 * Language: Java
 * Author: CodeByTushu
 */
class Solution {
    public int mirrorDistance(int n) {
        int temp = n;
        long reversed = 0;
        
        while (temp > 0) {
            reversed = reversed * 10 + (temp % 10);
            temp /= 10;
        }
        
        return (int) Math.abs(n - reversed);
    }
}

TIME COMPLEXITY

O(log10(N))

SPACE COMPLEXITY

O(1)

TOPICS

Math Simulation