Solution in Python


  • 0
    S

    '''
    def reverse(self, x):

        if x < 0:
            neg=True
            x= x*(-1)
        else:
            neg=False
        
        result=0
        while x>0:
            result*=10
            result+= x%10
            x//=10
            
        if neg:
            result= result*(-1)
            
        if (result<-2147483648) or (result>2147483647):
            result=0
            
        return result
    

    '''


Log in to reply
 

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