class Solution {
public:
int reverse(int x) {
bool isNeg = false;
if(x < 0) {
x = -x;
isNeg = true;
}
int c = 0;
while(x){
if(c > INT_MAX/10) return 0;
else c *= 10;
if(c > INT_MAX - x%10) return 0;
else c += x%10;
x /= 10;
}
if(isNeg) return -c;
return c;
}
};