Solution in python


  • 0
    M
    class Solution(object):
        def reverse(self, x):
            reverse = 0
            if x>0:
                while x>0:
                    remainder = x % 10
                    reverse = (reverse * 10) + remainder
                    x = x//10
                if reverse < 2147483647:
                    return reverse
                else:
                    return 0
            elif x<0:
                n = abs(x)
                while n>0:
                    remainder = n % 10
                    reverse = (reverse * 10) + remainder
                    n = n//10
                    if reverse < 2147483647:
                    return -reverse
                else:
                    return 0
            else:
                return 0
    

Log in to reply
 

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