首页 > 代码库 > LeetCode Pow(x,n)

LeetCode Pow(x,n)

class Solution {
public:
double pow(double x,int n)
{
  if(n<0)return 1.0/power(x,-n);
  return power(x,n);
    
}
    double power(double x, int n) {
       if(n == 0) return 1;
        double temp = power(x, n/2); 
        if(n % 2 == 0)
            return temp * temp;
        else
            return temp * temp * x;
    }
};

LeetCode Pow(x,n)