Solution in python


  • 0
    A
    class Solution:
        def reverse(self, x):
            sign = 1 if x > 0 else -1
            x = sign*x
            
            output = 0
            while x > 0:
                last_digit = x%10
                output = output*10 + last_digit
                x = int(x/10)
                
            output = sign*output
            
            if output <= 2**31-1 and output >= -2**31:
                return output
            else:
                return 0
    

Log in to reply
 

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