class Solution {
public:
int reverse(int x) {
int flag = x>0 ? 1 : -1;
int X = abs(x);
long long result = 0;
while (X)
{
result = result * 10 + X % 10;
X /= 10;
}
if (flag*result > INT_MAX||flag*result < INT_MIN)
return 0;
else
return flag * result;
}
};
Leetcode Reverse Integer
最新推荐文章于 2024-08-29 16:23:51 发布