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