My python code


  • 0
    M
    class Solution:
        def reverse(self, x):
            """
            :type x: int
            :rtype: int
            """
            
            if x == 0:
                return 0
            
            negative = ""
            if x < 0:
                negative = "-"
                x = x * -1
            
            while x % 10 == 0:
                x = int(x / 10)
            
            result = int(negative + str(x)[::-1])
            if result < -pow(2,31) or result > pow(2,31) - 1 :
                return 0
            else:
                return result
    

Log in to reply
 

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