题解 | #数值的整数次方#

数值的整数次方

http://www.nowcoder.com/practice/1a834e5e3e1a4b7ba251417554e07c00

public class Solution {
    public double Power(double base, int exponent) {
        if(exponent<0){
            base = 1/base;
            exponent *= -1;
        }
        double ans = 1;
        while(exponent>0){
            if((exponent&1)==1)
                ans = ans * base ;
            base = base * base;
            exponent = exponent>>1;
        }
        return ans;
  }
}

知识点:快速幂

见博客

全部评论

相关推荐

人快好乐家:这个是不是就是互联网公司说的提供就业岗位的搞法,因为上面压力给到了说要提供岗位,所以让学生来提前实习,到点了全都开掉
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务