Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
对一个整数进行逆序,题目很简单,直接给出代码。
AC code:
class Solution {
public:
int reverse(int x)
{
int sign=x<0?-1:1;
x*=sign;
int temp=0;
while(x>0)
{
temp=temp*10+x%10;
x/=10;
}
return sign*temp;
}
};