Implement pow(x, n).
考虑集中边角的情况,其余递归
x=0, n<0 等
class Solution {
public:
double pow(double x, int n) {
if (x==0)
return 0;
if (n<0)
return 1./myPow(x,-n);
else
return myPow(x,n);
}
double myPow(double x, int n)
{
double tmp;
if (n==0)
return 1;
tmp=myPow(x,n/2);
if (n%2)
return x*tmp*tmp;
else
return tmp*tmp;
}
};