pow(double x,int n)

来源:互联网 发布:直播实时转播软件 编辑:程序博客网 时间:2024/05/17 04:01
class Solution {public:    double myPow(double x, int n) {        if(n==0) return 1;        if(n==1) return x;        if(x==1) return 1;        if(n>0){        if(n&1){            return myPow(x*x,n/2)*x;        }        else{            return myPow(x*x,n/2);        }        }        if(n<0){        int  nn=-n;        double xx=1/x;        if((nn)&1){            return myPow(xx*xx,nn/2)*xx;        }        else{            return myPow(xx*xx,nn/2);        }        }    }};

0 0
原创粉丝点击