int reverse(int x) {
int y = (x < 0) ? -x : x;
int temp[10] = { 0 }, i = 0, j = 0;
while (y > 0)
{
temp[i] = y % 10;
y /= 10;
i++;
}
double res = 0;
while (i > 0)
{
i--;
res += temp[j] * pow(10.0, i);
j++;
}
res = (x < 0) ? -res : res;
if (res > pow(2.0, 31) - 1 || res < -pow(2.0, 31))
return 0;
return res;
}
7. Reverse Integer
最新推荐文章于 2024-10-17 19:06:39 发布