leetcode-----50. Pow(x, n)

代码

class Solution {
public:
    #define LL long long
    double myPow(double x, int n) {
        double ans = 1, p = x;
        LL t = abs((LL)(n));
        for (; t; t >>= 1) {
            if (t & 1) {
                ans = ans * p;
            }
            p = p * p;
        }
        return n > 0 ? ans : 1 / ans;
    }
};
原文地址:https://www.cnblogs.com/clown9804/p/13257676.html