python solution beats ~94%


  • 0
    Y
    class Solution(object):
        def reverse(self, x):
            """
            :type x: int
            :rtype: int
            """
            if x<0:
                return -self.reverse(-x)
            n = x
            tmp = 0
            while n:
                digit = n%10
                tmp = tmp*10+digit
                n/=10
            return tmp if abs(tmp)< 2147483648 else 0

Log in to reply
 

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