class Solution {
public int reverse(int x) {
StringBuilder res = new StringBuilder();
boolean flag = false;
if (x < 0) {
flag = true;
x *= -1;
}
if (x == 0) {
return x;
}
while (x > 0) {
res.append(x % 10);
x /= 10;
}
if (!flag) {
try {
return Integer.parseInt(res.toString());
} catch (Exception e) {
return 0;
}
} else {
try {
return Integer.parseInt(res.toString()) * -1;
} catch (Exception e) {
return 0;
}
}
}
}
11-13