码迷,mamicode.com
首页 > 其他好文 > 详细

LeetCode Pow(x,n)

时间:2014-12-03 21:19:09      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:leetcode

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)

标签:leetcode

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!