Palindrome Number — Number Theory & Geometry
Decide whether a signed integer's decimal digits form a mirror of themselves, working from the digits, not from text.
Number Theory & Geometry · Easy
The problem
An assay office stamps the same serial number at both ends of an ingot, and an inspector reads one stamp from each end. Decide whether an integer reads the same forwards and backwards in ordinary decimal notation, working with its digits only.
The story
A state assay office stamps a serial number at both ends of every metal ingot, so one stamp is read left to right and the other right to left. Given a signed 32-bit integer serial, decide whether its decimal digits read the same either way. A negative number never does, because of its minus sign. Work from the digits themselves, not from text.
What to return
- Return true if the digits of x form a palindrome, otherwise false.
- A negative number is never a palindrome because of its minus sign.
Constraints
- -2147483648 <= x <= 2147483647
Example
- Input
x = 4554- Output
true