(x int)
| 3 | import "math" |
| 4 | |
| 5 | func reverse(x int) int { |
| 6 | var out int64 |
| 7 | for x != 0 { |
| 8 | out = (out * 10) + int64(x%10) |
| 9 | x = x / 10 |
| 10 | } |
| 11 | |
| 12 | // if out overflows positive (2^32 - 1) or negative (-2^31) 32bit integer |
| 13 | if out > math.MaxInt32 || out < math.MinInt32 { |
| 14 | return 0 |
| 15 | } |
| 16 | |
| 17 | return int(out) |
| 18 | } |