Determine whether an integer reads the same forward and backward without converting it to a string if possible.
Problem
Given an integer x, return true if x is a palindrome, and false otherwise.
An integer is a palindrome when it reads the same from left to right and from right to left.
You should be careful about negative numbers and numbers ending in 0.
Goal
Write a function that checks whether the decimal representation of x is symmetric.
Input Format
- A single integer
x.
Output Format
- Return
trueifxis a palindrome, otherwise returnfalse.
Constraints
- The answer should be based on the base-10 representation of the integer.
Example 1
Input
x = 121
Output
true
Explanation
The number reads the same forward and backward.
Example 2
Input
x = -121
Output
false
Explanation
From left to right it is -121, but from right to left it would be 121-.
Show 1 more example
Example 3
Input
x = 10
Output
false
Explanation
The reversed form would be 01, which is not the same as 10.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.