```
public class Solution {
public int reverse(int x) {
if(x==0 || x==Integer.MIN_VALUE) return 0;
boolean positive = x>0;
if(!positive){
x *= -1;
}
long result = 0;
while(x>0){
result = result*10 + x%10;
x /=10;
}
if(positive){
return (result>Integer.MAX_VALUE)?0:(int)result;
}else{
result *= -1;
return (result<Integer.MIN_VALUE)?0:(int)result;
}
}
```

}