Accepted with golang


  • 0
    I

    we can juge whether a value is overflow by compare adjacent value.

    func reverse(x int) int {
        var rst int32 = 0 
        var next_rst int32
        for {
            if x != 0 { 
                next_rst = rst*10 + int32(x)%10
                x /= 10
                if next_rst/10 != rst {
                    rst = 0 
                    break
                }   
                rst = next_rst
            } else {
                break
            }   
        }   
        return int(rst)
    }
    

Log in to reply
 

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