解法一(36 ms 99.60%):
class Solution(object):
def reverse(self, x):
"""
:type x: int
:rtype: int
"""
if x>=0:
temp=int(str(x)[::-1])
if temp>2**31-1:
return 0
else:
return temp
else:
temp=int('-'+str(-x)[::-1])
if temp<-2**31:
return 0
else:
return temp
网友评论