做题博客链接
https://blog.csdn.net/qq_43349112/article/details/108542248
题目链接
https://leetcode-cn.com/problems/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof/
描述
写一个函数,求两个整数之和,要求在函数体内不得使用 “+”、“-”、“*”、“/” 四则运算符号。
提示:
a, b 均可能是负数或 0
结果不会溢出 32 位整数
示例
输入: a = 1, b = 1
输出: 2
初始代码模板
class Solution {
public int add(int a, int b) {
}
}
代码
class Solution {
public int add(int a, int b) {
while (b != 0) {
int c = a & b;
a ^= b;
b = c << 1;
}
return a;
}
}