Problem
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.
Example 1:
1 |
|
Example 2:
1 |
|
Example 3:
1 |
|
Follow up:
Coud you solve it without converting the integer to a string?
Explanation
-
If the number is 0, we return
true
; if the number is negative, we returnfalse
. -
We can reverse the number, and compare it with the current number. If they are the same, that means the number is palindrome; else the number is not a palindrome.
Solution
1 |
|