剑指OFFER----面试题65. 不用加减乘除做加法
链接:https://leetcode-cn.com/problems/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof/
代码
class Solution {
public:
int add(int a, int b) {
int sum, carry;
while (b) {
sum = a ^ b;
carry = (unsigned int)(a & b) << 1;
a = sum;
b = carry;
}
return a;
}
};