Python Solution


  • 0
    P
    class Solution(object):
        def reverse(self, x):
            """
            :type x: int
            :rtype: int
            """
            print 'Input: {}'.format(x)
            sign = ''
            val = str(x)
            if val[0] == '-':
                val = val[1:]
                sign = '-'
            
            num = int(sign + val[::-1])
            
            if -2147483648 > num or num > 2147483647:
                return 0
            
            return num
    

Log in to reply
 

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