File: a-number-after-a-double-reversal/solution.py

Date: 2026-06-06

Time: 15:11

a-number-after-a-double-reversal/solution.py

Purpose

This file solves LeetCode 2119: A Number After a Double Reversal. Given a non-negative integer num, determine whether reversing its digits twice yields the original number. The file provides a single Solution class following LeetCode's expected interface.

Key Components

Solution.minOperations(self, num: int) -> bool — The core (and only) method. Despite the misleading name minOperations (likely a copy-paste artifact from the LeetCode template or an auto-generated stub), this function checks whether num survives a double digit-reversal.

The logic: return num == 0 or num % 10 != 0

Patterns

Mathematical reduction instead of simulation. Rather than actually reversing the number twice and comparing, the solution identifies the only case where double-reversal changes a number: when trailing zeros are present. Reversing 1200 gives 21 (leading zeros dropped), and reversing 21 gives 12 — not 1200. The solution reduces this to a single modular arithmetic check.

LeetCode convention. A Solution class with a single public method, no imports, no _main_ block. This is the standard shape every problem in the repo follows.

Dependencies

Imports: None. Pure arithmetic, no standard library usage.

Imported by: The "Imported By" list in the prompt is a red herring — those are hundreds of unrelated test files that likely share a common test runner import pattern (e.g., importing a Solution class from a sibling solution.py). The actual consumer is a-number-after-a-double-reversal/test_solution.py.

Flow

1. If num == 0, return True — reversing 0 twice gives 0.

2. Otherwise, check num % 10 != 0 — if the last digit is nonzero, no trailing zeros exist, so double-reversal is lossless. If the last digit is zero, trailing zeros will be stripped on the first reversal and can't be recovered.

Invariants

Error Handling

None. The function assumes valid input per LeetCode constraints. No exceptions are raised or caught.