pow(x,n)

来源:互联网 发布:medea软件 编辑:程序博客网 时间:2024/06/01 07:22

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));    }}

http://blog.csdn.net/fengbingyang/article/details/12236121

0 0
原创粉丝点击