/*
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
Reverse digits of an integer.
Example1: x = 123, return 321
Example2: x = -123, return -321
*/
这个题目比较简单~
贴代码
class Solution {
public:
int reverse(int x) {
int i,s = 0;
for(i = 0; x != 0; i++)
{
s = (s+x % 10)*10;
x = x / 10;
}
if(x < 0)
s = -s;
return s/10;
}
};