给你个整数问是不是回文数,负数因为有-不算回文,要求用O1的空间,Python大法好,不用考虑溢出的问题,直接把数倒着复制一遍然后比较是否相等就行了
class Solution(object):
def isPalindrome(self, x):
"""
:type x: int
:rtype: bool
"""
if x<0:return False
ans=0
newx=x
times=1
while newx>0:
t=newx%10
ans=ans*10+t
newx/=10
if ans==x:return True
else:return False