这题啥也不说了,简单…… 记一下代码。
要通过测试,主要就是处理一下正负号。
class Solution {
public:
int reverse(int x) {
// Note: The Solution object is instantiated only once and is reused by each test case.
int result = 0;
int sign = x < 0 ? -1 : 1;
x *= sign;
while (x > 0) {
/*if (result == 214748364) {
if (sign == -1) {
if (x > 8) return 0;
} else {
if (x > 7) return 0;
}
} else if (result > 214748364) return 0;*/
result = (result * 10) + (x % 10);
x /= 10;
}
result *= sign;
return result;
}
};