1,题目描述
2,题目分析
总结:注意溢出 ,设置最大和最小如果溢出了返回0。刚开始没有考虑溢出
数的反转想到的是10操作
3,代码实现
class Solution {
public:
int reverse(int x)
{
//https://zhuanlan.zhihu.com/p/24738932
const int int_max=0x7fffffff;
const int int_min=0x80000000;
long long anwser=0;
while(x!=0)
{
anwser=anwser*10+(x%10);
x/=10;
}
if(anwser<int_min || anwser>int_max)
{
anwser=0;
}
return anwser;
}
};