10 lines Python solution


  • 0
    M
    class Solution:
        def reverse(self, x):
            """
            Given a 32-bit signed integer, reverse digits of an integer.
            :type x: int
            :rtype: int
            """
            if x < 0:
                x = -x
                xstring = '-' + str(x)[::-1]
            else:
                xstring = str(x)[::-1]
    
    
            if int(xstring) < -2147483648 or int(xstring) > 2147483647:
                xstring=0
        
            return(int(xstring))

  • 0
    M
    This post is deleted!

Log in to reply
 

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