leetcode007. Reverse Integer

时间:2021-08-31 09:28:10
 /* a good way to predict overflow
* each time *10 must predict int overflow
* not only the last time to predict which will be wrong.
*/
class Solution {
public:
int reverse(int x) {
if(x==)return x;
int tag=;
long int re=;
if(x<)
{
tag=;
x=-x;
}
while(x)
{
int tmp=re*+x%;
if((tmp-x%)/!=re)return ;
re=tmp;
x=x/;
}
if(tag)re=-re;
return re;
}
};