Go
func isPalindrome(x int) bool {
if x < 0 {
return false
}
res, val := 0, x
for x != 0 {
res = res * 10 + x % 10
x /= 10
}
return res == val
}
Python3
class Solution:
def isPalindrome(self, x: int) -> bool:
if x < 0 : return False
val, res = x, 0
while x:
res = res * 10 + x % 10
x //= 10
return res == val
class Solution:
def isPalindrome(self, x: int) -> bool:
return str(x) == str(x)[::-1]