class Solution {
public:
double myPow(double x, int n) {
if(n<0)
{
long long a = -(long long)n;
double temp = dfs(x,a);
return 1.0/temp;
}
else
{
double temp = dfs(x,n);
return temp;
}
}
double dfs(double x,int n)//给一个数,给一个n,求出x的n次幂
{
//递归结束条件
if(n == 0) return 1;
//子问题
double temp = dfs(x,n/2);//求出一半的幂
//返回相乘结果
if(n%2 == 0) return temp*temp;
else return temp*temp*x;
}
};