Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.
Example 1:
Input: 121
Output: true
Example 2:
Input: -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
Example 3:
Input: 10
Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
Follow up:
func isPalindrome(x int) bool {
var Result bool = false
if x < 0 {
return Result
}
var copyX int = x
var reverse int = 0
for x > 0 {
var mod int = x%10
reverse = reverse * 10 + mod
x = x/10
}
if copyX == reverse {
Result = true
}
return Result
}
class Solution:
def isPalindrome(self, x):
"""
:type x: int
:rtype: bool
"""
result = False
reverse = 0
copyX = x
if(x < 0):
return result
while(x > 0):
mod = x%10
reverse = reverse * 10 + mod
x = int(x/10)
if copyX == reverse:
result = True
return result