my Go solution


  • 0
    L

    My Go solution,but I think my code haven't handle overflow even if has pass.

    package reverse
    
    import "math"
    
    func reverse(x int) int {
    	var right int64
    	for x != 0 {
    		right *= 10
    		right = right + int64(x)%10
    		if right > math.MaxInt32 || right < math.MinInt32 {
    			return 0
    		}
    
    		x = x / 10
    	}
    	return int(right)
    
    }
    

Log in to reply
 

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