实在看不下去大家直接用Math.random()了,我们的JS照样也可以写出有深度的算法好嘛,别再投机取巧了

数值的整数次方

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

function Power(base, exponent)
{
    if(exponent<0){
        base=1/base;
        exponent=-exponent;
    }
    let res=1;
    while(exponent>0){
        if((exponent&1)==1) res*=base;
       // exponent=exponent>>1;
         exponent>>=1;
        base*=base;
    }
    return res;
}
全部评论
投机用了Math.pow,然后试了一下这层的代码,发现空间和时间上面都不如pow啊,是因为这道题刚出的时候没有pow吗
点赞 回复 分享
发布于 2021-03-25 22:22

相关推荐

不愿透露姓名的神秘牛友
07-08 13:05
点赞 评论 收藏
分享
Gaynes:查看图片
点赞 评论 收藏
分享
07-09 18:28
门头沟学院 Java
写着提前批,结果还要实习4个月以上???
程序员牛肉:这种不用看,直接投了,面试的时候问对应的HR就行。有可能他们是直接复制的暑期实习的模板。
点赞 评论 收藏
分享
评论
3
收藏
分享

创作者周榜

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