My Py3 Solution


  • 0
    S
    def reverse(self, x):
        neg = False
        if x < 0:
            neg = True
        if -9 <= x <= 9:
            return x        
        rev = 0
        x = abs(x)
        while x != 0:
            rev = rev * (10) + (x % 10)
            x //= 10
    
        if rev >= 1<<31:
            return 0
        
        if neg:
            return rev * -1
    
        return rev

Log in to reply
 

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