7. Reverse Integer
https://leetcode.com/problems/reverse-integer/
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
class Solution {
public:
int reverse(int x) {
int y=0;
int MAX = 214748364;
int MIN = -214748364;
while (x / 10 != 0)
{
y = y * 10 + x % 10;
x = x / 10;
}
if (y >MAX||y<MIN)
{
y = 0;
}
else{
y = y * 10 + x % 10;
}
return y;
}
};