class Solution {
public:
int reverse(int x) {
bool minus = x < 0;
if (x == -2147483648)
{
return 0;
}
x = x < 0 ? -x : x;
char ch[15];
sprintf(ch,"%d", x);
int length = strlen(ch);
for(int i = 0; i < length / 2; i++)
{
swap(ch[i], ch[length - i - 1]);
}
long long result = atoll(ch);
if(result > pow(2,31) - 1)
{
return 0;
}
result = minus ? -result : result;
return result;
}
};