class Solution(object):
def reverse(self, x):
"""
:type x: int
:rtype: int
"""
maxInt = 2**311
minInt = 1 * 2**31
if x < 0:
y = 1 * int(str(x)[::1])
else:
y = int(str(x)[::1])
if y > maxInt or y < minInt:
return 0
return y
Solution in Python

class Solution: def reverse(self, x): """ :type x: int :rtype: int """ a = x a = x if(a<0): a=a digits=[] while(a != 0): digits.append(a%10) a = (a(a%10))/10 sum = 0 for i in range(len(digits)): sum += (10**i)*digits[len(digits)i1] if(x<0 and sum<=2**31): return int(1*sum) elif(x>0 and sum<=(2**31)1): return int(sum) else: return 0

class Solution(object): def reverse(self, x): """ :type x: int :rtype: int """ sign = 1 result = 0 if x < 0: sign = 1 x *= 1 num_len = len(str(x))  1 while x != 0: reminder = x % 10 x = x // 10 result += reminder * (10 ** num_len) num_len = 1 if result < 2147483648 or result > 2147483647: result = 0 return result*sign