LeetCode Pow(x,n)

时间:2014-12-03 21:17:26   收藏:0   阅读:140
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;
    }
};

原文:http://blog.csdn.net/wdkirchhoff/article/details/41703049

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!