题目链接:
https://leetcode.cn/problems/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof/description/?favorite=xb9nqhhg
代码:
class Solution {
public:
int add(int a, int b) {
while(b)
{
unsigned int carry=(unsigned int)(a&b)<<1;
a=a^b;
b=carry;
}
return a;
}
};
该篇内容是关于LeetCode中的一道题目,要求不使用加法运算符实现两个整数的加法。解决方案是利用位操作,通过循环和位与、位异或及左移操作来完成加法过程。
338

被折叠的 条评论
为什么被折叠?



