Open fly0o0 opened 4 years ago
/**
* @param {number} a
* @param {number} b
* @return {number}
*/
var add = function(a, b) {
while (b != 0) {
// 进位,(a + b) % 2
let carrySum = (a & b) << 1
// 非进位,a + b
let sum = a ^ b
a = sum
b = carrySum
}
return a
};