2 liner in Python - beats 93%


  • 0
    Y
    class Solution(object):
        def reverse(self,x):
            reversedInt=int(str(x)[::-1]) if x>=0 else int('-'+str(x)[1:][::-1])
            #Python doesn't have INT overflow but just to handle the case when the reversed string is not in the 32-bit Int limit 
            return reversedInt if (-1)*2**31<reversedInt<(2**31-1) else 0
    

Log in to reply
 

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