Pow(x, n)
class Solution {
public:
double myPow(double x, int n) {
//使用什么方法呢,使用二分查找算法
long long N=n;
if(N<0)
return PoW(1/x,-N);
else if(N==0)
return 1.0;
else
return PoW(x,N);
}
double PoW(double x,int N)
{
if(N==0)//自己一开始的判断条件是N==1 return x出错
return 1.0;
double half=PoW(x,N/2);
if(N%2!=0)
return half*half*x;
else
return half*half;
}
};