题目
方法:
还是Python的切片的方法,负数直接返回False,切片时需要注意[::]中所对应的index序号。
class Solution:
def isPalindrome(self, x):
"""
:type x: int
:rtype: bool
"""
if x < 0:
result = False
elif len(str(x)) % 2 == 0:
y = str(x)[:int(len(str(x)) / 2) - 1:-1]
if y == str(x)[:int(len(str(x)) / 2)]:
result = True
else:
result = False
else:
y = str(x)[:int((len(str(x)) + 1) / 2) - 1:-1]
if y == str(x)[:int(len(str(x)) / 2)]:
result = True
else:
result = False
return result