class Solution {

func reverse(_ x: Int) -> Int {

```
var result:Int32 = 0
var temp = abs(Int32(x))
while temp != 0 {
let _result = result
result = result &* 10 &+ temp % 10
//check: overflow exists
if (result - result % 10) / 10 != _result {
return 0
}
temp = (temp - temp % 10) / 10
}
return x < 0 ? Int(-result) : Int(result)
```

}

}