Accepted python code: see (a) solution for the overflow issue here


  • 0
    H
        def reverse(self, x):
            """
            :type x: int
            :rtype: int
            """
            neg = False
            if x < 0:
                neg = True
    
            x = ''.join(str(abs(x)))
            x = x[::-1]
    
            if neg:
                x = '-'+x
    
            x = int(x)
            if x > 2147483647 or x < -2147483647:
                return 0
    
            return x
    

    I assume other python folks are going to have issues with the overflow (not really relevant in our case, and not specified in the directions).


Log in to reply
 

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