版权声明:原创勿转 https://cloud.tencent.com/developer/article/1412887
思路
循环取余数
需要注意越界
code
代码语言:javascript复制func reverse(x int) int {
res := 0
for x != 0 {
carry := x % 10
res = res*10 carry
if res > math.MaxInt32 || res < math.MinInt32 {
return 0
}
x /= 10
}
return res
}