class Solution {
public:
int reverse(int x) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int sign = 1;
if(x < 0) sign = -1;
unsigned int num = x < 0 ? -x : x;
int ans = 0;
while (num != 0)
{
ans = ans*10 + num%10;
num /= 10;
}
return ans*sign;
}
};
[LeetCode]Reverse Integer
最新推荐文章于 2021-01-12 00:40:21 发布