Easy Python solution


  • 0
    T
    class Solution:
        def reverse(self, x):
            """
            :type x: int
            :rtype: int
            """
            if x<0:
                return -self.reverse(-x)
            new_num = 0
            while x:
                new_num = x%10 + new_num*10
                x = x//10
            if new_num>2147483647:
                return 0
            return new_num
    

Log in to reply
 

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