标签:
class Solution {
public:
int reverse(int x) {
long long res = 0;
long long num = 0;
int flag = 1;
if (x < 0)
{
num = num-x;//此处不能写作0-x或者-x,num-x这个表达式实际上存在一个隐式转换
flag = -1;
}
else
{
num = x;
}
while (num)
{
res = res*10 + num % 10;
num = num / 10;
}
if (res > INT_MAX)
{
return 0;
}
return res*flag;
}
};
标签:
原文地址:http://www.cnblogs.com/flyjameschen/p/4317292.html