Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
class Solution {
public:
int reverse(int x) {
int y=x>=0?x:-x;
int nResult=0;
while(y/10>0)
{
nResult=nResult*10+y%10;
y=y/10;
}
nResult=nResult*10+y;
return x>=0?nResult:-nResult;
}
};