[leetcode] 7. Reverse Integer (easy)
水题 唯一注意的点就是数字溢出
class Solution
{
public:
int reverse(int x)
{
long long MAX = ((long long)1 << 31) - 1;
long long MIN = 0 - (1 << 31);
long long a = 0;
while (x)
{
a = a * 10 + x % 10;
x /= 10;
}
return a > MAX || a < MIN ? 0 : a;
}
};