My 60ms python solution.


  • 0
    Y
    def reverse(self, x):
        y=abs(x)    
        string=str(y)
        result=int(string[::-1])
        if result < 2147483648:
            if x<0:
                return -1*result
            else:
                return result
        else:
            return 0

  • 0
    D

    a good example of using python slice to reverse a string.


Log in to reply
 

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