题解 | #不用加减乘除做加法#

不用加减乘除做加法

https://www.nowcoder.com/practice/59ac416b4b944300b617d4f7f111b215

function Add(num1, num2) {
    // write code here
    let x, y;
    while (num2 !== 0) {
        x = num1 ^ num2;
        y = (num1 & num2) << 1;
        num1 = x;
        num2 = y;
    }
    return num1;
}
module.exports = {
    Add: Add,
};

全部评论

相关推荐

吴offer选手:我卡在笔试才是最好笑的,甚至没给我发过笔试链接
投递哔哩哔哩等公司6个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务