pwstrick / daily

一份搜集的前端面试题目清单、面试相关以及各类学习的资料(不局限于前端)
2.39k stars 242 forks source link

两整数之和 #1032

Open pwstrick opened 4 years ago

pwstrick commented 4 years ago

371. 两整数之和

/**
 * @param {number} a
 * @param {number} b
 * @return {number}
 */
var getSum = function(a, b) {
    let sum;
    while(b != 0) {
        sum = a ^ b;
        b = (a & b) << 1;
        a = sum;
    }
    return a;
};