Palindrome Number Check
easySave
MathNumber Theory
Given an integer, write a function to determine if it is a palindrome. An integer is a palindrome when it reads the same backward as forward. For example, 121 is a palindrome, but 123 is not.
Example 1
Input
[ 121 ]
Output
true
Explanation. 121 reads as 121 backwards, which makes it a palindrome.
Example 2
Input
[ -121 ]
Output
false
Explanation. Negative numbers cannot be palindromes by definition.
Example 3
Input
[ 10 ]
Output
false
Explanation. 10 reads as 01 backwards which is not the same.
Example 4
Input
[ 1221 ]
Output
true
Explanation. 1221 reads as 1221 backwards, which makes it a palindrome.
Follow-up: Can you solve the problem in O(1) space complexity?
Constraints:
You must not convert the integer into a string to solve this problem. The input integer could be negative, but negative numbers cannot be palindromes.
- Views
- 3