Use Python's `[::-1]` operation.(3 lines)


  • 0
    S

    Use Python's [::-1] operation.

    class Solution:
        def reverse(self,x):
            ans = int(str(x)[::-1]) if x>0 else int(str(abs(x))[::-1])*(-1)
            return 0 if ans>2**31-1 or ans<-2**31 else ans 
    

Log in to reply
 

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