标签:
class Solution {
public:
double pow(double x, int n) {
}
};
考虑
class Solution {
public:
double pow(double x, int n) {
double res=1.0;
if(n<0)
{
x=1/x;
n = -n;
}
while(n>0)
{
if(n&1 == 1)
{
res *= x;
}
x *= x;//求出x的1、2、4、8……32次
n = n>>1;
}
return res;
}
};
标签:
原文地址:http://www.cnblogs.com/flyjameschen/p/4314933.html