class Solution {
public:
int reverse(int x) {
// Note: The Solution object is instantiated only once and is reused by each test case.
int res=0;
int flag=1;
if (x<0) {
flag=-1;
x=x*(-1);
}
while(x>=10) {
res +=x%10;
x=x/10;
res=res*10;
}
res+=x;
if (flag==-1) {
res=res*(-1);
}
return res;
}
};
Reverse integer
最新推荐文章于 2022-09-18 19:57:18 发布