Python Solution by Converting int to string


  • 0
    F
    class Solution(object):
        def reverse(self, x):
            """
            :type x: int
            :rtype: int
            """
            max32Bit, min32Bit = (2**32 - 1) / 2, - (2**32 - 1) / 2
            if x < 0:
                res = -int(str(-x)[::-1])
            else:
                res = int(str(x)[::-1])
    
            if res > max32Bit or res < min32Bit:
                res = 0
            return res
    

Log in to reply
 

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