Login dark
class Solution:
    def reverse(self, x: int) -> int:
        MAX = 2 ** 31 -1
        MIN = -2 ** 31
        try:
            ret = int(str(x)[::-1].strip('-').lstrip('0'))
            if x < 0:
                ret = ret * -1
        except:
            return 0
        if ret > MAX or ret < MIN:
            return 0
        return ret