pow

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

推荐阅读更多精彩内容