7. Reverse Integer (整数的溢出)

时间:2021-11-19 23:25:56

Reverse digits of an integer.

Example1: x = 123, return 321
Example2: x = -123, return -321

For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.

int reverse(int x) {
if(x == INT_MIN){//-2147483648
return ;
} bool pos = x>= ? true:false;
x = abs(x);
long int ret = ; while(x>){
ret = ret* + x%;
if(ret > INT_MAX ) return ;
x /= ;
}
if(!pos) ret = -ret;
return ret;
}