整数逆序
class Solution:
def reverse(self, x):
"""
:type x: int
:rtype: int
"""
if x < -pow(2, 31) or x > pow(2, 31) - 1:
x = 0
isNegative = (x < 0)
if isNegative:
x = 0 - x
if x >= pow(2, 31):
x = 0
result = 0
while x > 0:
result = result * 10 + x % 10
x = int(x / 10)
if isNegative:
result = 0 - result
if result < -pow(2, 31) or result > pow(2, 31) - 1:
result = 0
print(result)
return result








网友评论