Solution in Go


  • 0
    N
    func reverse(x int) int {
        const MaxInt32 = (1 << 31) - 1
        const MinInt32 = -(1 << 31)
        y := 0
        for x != 0 {
            y = y * 10 + (x % 10)
            x /= 10
            if y > MaxInt32 || y < MinInt32 {
                return 0
            }
        }
       
        return y
    }
    

Log in to reply
 

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