reverse number
class Solution {
public:
int reverse(int x) {
bool negative_flag=false;
if(x==INT_MIN)
return 0;
if(x<0)
{
x=-x;
negative_flag=true;
}
long long result=0;
while(x!=0)
{
result=result*10+x%10;
x=x/10;
}
if(result>INT_MAX)
return 0;
if(negative_flag)
return -result;
else
return result;
}
};
posted on 2015-05-09 18:04 pugongyingyehuifei 阅读(132) 评论(0) 编辑 收藏 举报