您的位置:首页 > 其它

LeetCode Reverse Integer

2014-06-01 20:48 288 查看
题目链接:https://oj.leetcode.com/problems/reverse-integer/

Reverse digits of an integer.

Example1: x = 123, return 321

Example2: x = -123, return -321

不解释

class Solution {
public:
int reverse(int x) {
bool flag=false;
if(x<0) flag=true;
x=abs(x);
int ans=0;
while(x)
{
ans=ans*10+x%10;
x/=10;
}
if(flag)
ans=-ans;
return ans;
}
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: