50. Pow(x, n)
程序员文章站
2022-07-15 12:47:57
...
double myPow(double x, int n) {
if (x == 0)
return 0;
long long val = n;
double res = 1.0;
if (val < 0)
x = 1 / x, val = -val;
while (val > 0) {
if ((val & 1) == 1)
res *= x;
x *= x;
val >>= 1;
}
return res;
}
上一篇: 50. Pow(x, n)
下一篇: 50. Pow(x, n)