python maths solution


  • 0
    A

    '''
    class Solution:
    def reverse(self, x):
    """
    :type x: int
    :rtype: int
    """

        r=0
        flag = 1
        if x <0:
            flag=-1
            x=x*-1
            
        while x >0:
          r = r*10+x%10
          x=x//10
        if (abs(r*flag)>2**31):
            return 0
        else:
            return r*flag
    

    '''


Log in to reply
 

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