0
点赞
收藏
分享

微信扫一扫

2022-01-09(剑指 Offer 16. 数值的整数次方)

Sikj_6590 2022-01-09 阅读 23
java
class Solution {
    public double myPow(double x, int n) {
        if(x == 0) return 0;
        long b = n;
        double res = 1.0;
        if(b < 0) {
            x = 1 / x;
            b = -b;
        }
        while(b > 0){
            if((b & 1) == 1){
                res *= x;
            }
            x *= x;
            b >>= 1;
        }
        return res;
    }
}
举报

相关推荐

0 条评论