class Solution {
public:
int reverse(int x) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
int ret;
int sign = (x < 0);
if (sign) {
x = -x;
}
ret = 0;
while (x) {
ret *= 10;
ret += x % 10;
x /= 10;
}
if (sign) {
ret = -ret;
}
return ret;
}
};
Reverse Integer
最新推荐文章于 2022-09-18 19:57:18 发布