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

*Pow(x, n)

时间:2015-12-31 07:15:11      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

Implement pow(xn).

public class Solution {
        public double myPow(double x, int n) {
        if(n == 0)
            return 1;
        if(n<0){
            n = -n;
            x = 1/x;
        }
        return (n%2 == 0) ? myPow(x*x, n/2) : x*myPow(x*x, n/2);
    }
}

 

 

https://leetcode.com/discuss/17005/short-and-easy-to-understand-solution

 

*Pow(x, n)

标签:

原文地址:http://www.cnblogs.com/hygeia/p/5090544.html

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