Solution in Python


  • 0
    D
    class Solution(object):
        def reverse(self, x):
            """
            :type x: int
            :rtype: int
            """
            maxInt = 2**31-1
            minInt = -1 * 2**31
            if x < 0:
                y  = -1 * int(str(-x)[::-1])
            else:
                y  = int(str(x)[::-1])
            if y > maxInt or y < minInt:
                return 0
            return y
    

Log in to reply
 

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