My accepted code for python


  • 0
    A

    class Solution:
    def reverse(self, x):
    """
    :type x: int
    :rtype: int
    """
    new = 0
    if x <0:
    temp= -1
    else:
    temp = 1
    x = abs(x)

        while (x!=0):
            new = new*10+ x%10
            x = int(x/10)
        
        if new > 2147483647:
            return 0
        return new*temp

Log in to reply
 

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