```
public int reverse(int x) {
if(x == 0 || x == Integer.MIN_VALUE) return 0;
while(x % 10 == 0) x /=10;
StringBuilder s = new StringBuilder(String.valueOf(Math.abs(x)));
if(x < 0) s.append("-");
String res = s.reverse().toString();
Long l = Long.parseLong(res);
if( l > Integer.MAX_VALUE || l < Integer.MIN_VALUE) return 0;
return Integer.parseInt(res);
}
```