Not sure what to do here, anyone know what's up? I'm trying to find if a number is a palindrome, and I'm getting hung up with the input -121
. The output should be 'false'
, as in it is not a palindrome, whereas 121
is.
LeetCode code:
class Solution:
def isPalindrome(self, x: int) -> bool:
x = str(x)
xrev = x[::-1]
if x == xrev:
return 'true'
else:
return 'false'
This returns 'true', 'false' is expected. Whereas my code ran on Atom returns 'false' as expected:
def isPalindrome(x):
x = str(x)
xrev = x[::-1]
if x == xrev:
return 'true'
else:
return 'false'
print(isPalindrome(-121))