Simple Python Solution


  • 0
    H
    class Solution(object):
        def reverse(self, x):
            """
            :type x: int
            :rtype: int
            """
            if str(x)[0] == '-':
                number = int(str(x)[:0:-1])
                if (number > 2147483647):
                    return 0
                return -1 * number
    
            number = int(str(x)[::-1])
            if number > 2147483647:
                return 0
            return number
    

Log in to reply
 

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