```go
func reverse(x int) int {
y := int32(x)
var ans int32
for y != 0 {
temp := ans*10 + y%10
if temp/10 != ans {
return 0
}
ans = temp
y = y / 10
}
return int(ans)
}
```
#12楼@qclaogui LeetCode 上面的原型是` func reverse(x int) int `
LeetCode 接纳的一种写法如下,runtime 4ms
{
y := int32(x)
var ans int32
for y != 0 {
temp := ans*10 + y%10
if temp/10 != ans {
return 0
}
ans = temp
y = y / 10
}
return int(ans)
}
最近的评论