Skip to content
CodeShare
All problems

Palindrome Number

Check whether a number reads the same backward.

EasyMath

Given an integer x, return true if it reads the same forward and backward, and false otherwise.

Negative numbers are never palindromes: -121 reads as 121- backward. Can you solve it without turning the number into a string?

Examples

Example 1
Input
x = 121
Output
true
Example 2
Input
x = -121
Output
false
Why
Backward it reads 121-, which isn't the same.
Example 3
Input
x = 10
Output
false
Why
Backward it reads 01.

Constraints

  • -2^31 <= x <= 2^31 - 1