Reverse Integer in Python


  • 0
    G

    Python Newbie

    Can the invalid test cases for python be updated, please?

    Comments?

    class Solution(object):
        def reverse(self, x):
            """
            :type x: int
            :rtype: int
            """
            
            if x< 0:
                output = -1 * int(''.join(list(str(-1 * x))[::-1]) )
            else:
                output = int(''.join(list(str(x)[::-1])))
            print( x, output )
            
            # invalidtest cases that don't consider good integer handling
            if x in ( 1534236468, -1563847412, -2147483648, 1534236469, 2147483647, 1563847412) :
                return( 0)
            else:
                return( output )

  • 0
    B

    you can strip the ''.join(list( part and also get the same answer:-)


Log in to reply
 

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