Solution in Python


  • 0
    R
    def reverse(self, x):
        """
        :type x: int
        :rtype: int
        """
        max = 2**31-1
        if x > max > 0 or x < -max < 0:
            return 0
        x = x.__str__()[::-1]
        if '-' in x:
            x = -int(x[0:-1])
            if x < -max:
                return 0
        elif int(x) > max > 0:
            return 0
        return int(x)
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.