#
# 
# @param x int整型 
# @return int整型
#
class Solution:
    def reverse(self , x ):
        # write code here        
        n = 0

        flag = x>0
        x = abs(x)
        t = x
        while t!=0:
#             a = x/10
            t = t/10
            n += 1
        t = x
        res = 0
        while t!=0:            
            res += (t%10) * (10**(n-1))
            t = t/10
            n -= 1
        if not flag:
            res = (-1)*res
        if res > 2**31-1 or res < -1 * (2**31):
            return 0
        return res