Easy to understand Python solution


  • 0
    def reverse(x):
     	    r=0
     	    neg=False
     	    if x<0:
     	    	neg=True
     	    	x=-x
     	    while not x==0:
     	    	r=r*10+x%10
     	    	x=x/10
     	    if r>=2**31:return 0
     	    if neg: r=-r	
     	    return r
    

Log in to reply
 

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