先将整型转换为字符列表,利用列表的反转方法,最后将字符列表转成整型
n = 98653214
s = list(str(n))
s.reverse()
reverse_num = int("".join(s))
print(reverse_num)
def reverse(self, x):
"""
:type x: int
:rtype: int
"""
num = 0
if x == 0:
return 0
if x < 0:
x = -x
while x != 0:
num = num*10 + x%10
x = x/10
num = -num
else:
while x != 0:
num = num*10 + x%10
x = x/10
if num>pow(2,31)-1 or num < pow(-2,31):
return 0
return num