```
public class Solution {
public int reverse(int x) {
long result = 0;
int tmp = Math.abs(x);
while(tmp>0){
result = result * 10;
result = result + tmp%10;
if(result>Integer.MAX_VALUE) {
return 0;
}
tmp = tmp/10;
}
return (int)(x>0?result:-result);
}
}
```