class Solution {
public:
int reverse(int x) {
bool isNeg = false;
if(x < 0) {
x = -x;
isNeg = true;
}
int c = 0;
while(x){
if(c > INT_MAX/10) return 0;
else c *= 10;
if(c > INT_MAX - x%10) return 0;
else c += x%10;
x /= 10;
}
if(isNeg) return -c;
return c;
}
};
Reverse Integer
最新推荐文章于 2022-09-18 19:57:18 发布