Reverse 32 bit signed integer solution - Python 2.7


  • 0
    I
    class Solution(object):
        def reverse(self, x):
            """
            :type x: int
            :rtype: int
            """
            signed=1
            if x!=abs(x):
                signed=-1
            num=abs(x)
            outp = 0
            while num!=0:
                temp=num%10
                outp=outp*10+temp
                num=num/10
            if outp > 2147483648 or x>2147483648:
                return 0
            return signed*outp
    

Log in to reply
 

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