class Solution {
public:
int reverse(int x) {
int positive = 1;
long long xx = x;
if (xx < 0) {
positive = -1;
xx = -xx;
}
long long y = 0;
while (xx) {
y = y * 10 + xx % 10;
xx /= 10;
}
y *= positive;
if (y < INT_MIN || y > INT_MAX)
return 0;
return y;
}
};