```
class Solution {
public int reverse(int x) {
int result = 0;
while(x != 0) {
if(result < -(Math.pow(2, 31) / 10) || result > Math.pow(2, 31) / 10)
return 0;
result = result * 10 + (x % 10);
x = x / 10;
}
return result;
}
}
```