reverse integer
int reverse_integer(int n) {
/* int sign = 1;
if(n < 0) { // handle sign is unnecessary!
n = -n;
sign = -1;
} */
long long res = 0; // gist, handle int overflow
while(n != 0) {
int last_digit = n%10; // note that -22%10 = -2, so no need to handle sign
res = 10 * res + last_digit;
n /= 10;
}
if(res > INT_MAX) return -1;
return (int)res;
}