Solution in Python.


  • 0
    Z
    class Solution:
        def reverse(self, x):
            maxInt = 2 ** 31 - 1
            minInt = -1 * 2 ** 31
    
            if type(x) == int:
                num = str(x)
    
            if '-' in num:
                num = num.strip('-')
                result = -int(num[::-1])
            else:
                result = int(num[::-1])
                
            if result > maxInt or result < minInt:
                return 0
            return result
    

  • 0
    Z
    This post is deleted!

Log in to reply
 

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