Python easy solution 55ms


  • 0
    P

    It's my solution to this problem!

    class Solution(object):
        def reverse(self, x):
            """
            :type x: int
            :rtype: int
            """
            x = str(x)
            hasOp = x[0]
            x = x[::-1]
            if (hasOp == '-'):
                x = '-' + x[:-1]
            x = int(x)
            if ((x <= (1 << 31)) and (x >= -1 << 31)):
                return x
            else: return 0
    

Log in to reply
 

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