代码如下:
class Solution():
def reserve(self,x):
if -10 < x < 10:
return x
str_x = str(x)
#整数不为负数
if str_x[0] != '-':
str_x = str_x[::-1]
x = int(str_x)
#整数为负数:
else:
str_x = str_x[1:][::-1]
x = int(str_x)
x = -x
# 三目运算符,判断是否溢出
# 如果-2147483648 < x < 2147483647则返回x,否则返回0
return x if -2147483648 < x < 2147483647 else 0
if __name__ =="__main__":
s = Solution()
reserve_int = s.reserve(-34324233)
print(reserve_int)