class Solution {
public:
int reverse(int x) {
int rev = 0;
while (x != 0) { //while里面的判定条件是若为0,则不进行,若非0.则进行
int pop = x % 10;
x /= 10;
if (rev > INT_MAX/10 || (rev == INT_MAX / 10 && pop > 7)) return 0;
if (rev < INT_MIN/10 || (rev == INT_MIN / 10 && pop < -8)) return 0;
rev = rev * 10 + pop;
}
return rev;
}
};
字符翻转
最新推荐文章于 2022-03-21 22:03:16 发布