题目:
class Solution {
public:
int add(int a, int b) {
while(b){ //总体思路:上一次产生的进位数*进制数+本位数,进制数为0的时候直接返回本位数即可
int carry = a&b; //计算进位
a = a^b; //计算本位
b = (unsigned)carry<<1; //做进位逻辑:乘以进制数
}
return a;
}
};
作者:疯子
链接:https://leetcode.cn/problems/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof/solutions/1103309/dian-zan-yao-wo-zhi-dao-ni-xiang-kan-dia-ovxy/
来源:力扣(LeetCode)