class Solution(object):
def reverse(self, x):
"""
:type x: int
:rtype: int
"""
isPositive = x >= 0
x = abs(x)
res = 0
while x != 0:
res = res * 10 + x % 10
x /= 10
res = res if isPositive else -res
if res > 0x7fffffff or res < -(0x80000000):
return 0
return res
https://leetcode.com/problems/reverse-integer/
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321