Show problems as
Classic problem #9EasyMath

Palindrome Number

Real-world version: Mirrored Meter Reading
Tracked in this browser only
Read Palindrome Number on LeetCode(opens in a new tab)

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

A two-way flow meter shows one signed whole number, reading. Flow drawn off the main drives the counter up and flow pushed back into the main drives it down, so the display can sit below zero.

The control room marks a reading as mirrored when its digits run the same way in both directions: sweeping the display from the left gives the same digit sequence as sweeping it from the right. The minus sign is printed only at the leading edge of the display and never at the trailing edge, so anything below zero cannot be mirrored. A reading of one digit, zero included, is mirrored.

Return true for a mirrored reading, false for anything else.

The meter firmware ships without any text handling, so your routine has to work on the number arithmetically. Converting the reading into characters and inspecting them is not available to you.

Examples

Example 1

Input
reading = 4884
Output
true

Sweeping left to right gives 4, 8, 8, 4 and sweeping the other way gives the same sequence.

Example 2

Input
reading = -717
Output
false

The digits alone would match, but the minus sign sits only at the leading edge, so the display cannot read alike in both directions.

Example 3

Input
reading = 250
Output
false

From the right the digits run 0, 5, 2, which is not the sequence 2, 5, 0.

Constraints

  • -2^31 <= reading <= 2^31 - 1
  • No conversion of the reading to a string is permitted

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 is_mirrored(reading: int) -> bool:
Java
public boolean isMirrored(int reading)