50. Pow(x, n)

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

 

posted @ 2017-09-25 09:17  Weiyu Wang  阅读(147)  评论(0编辑  收藏  举报