Straightforward solution in Python


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

Log in to reply
 

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