问:
给你两个整数 a 和 b ,不使用 运算符 + 和 - ,计算并返回两整数之和。
原题链接:https://leetcode.cn/problems/sum-of-two-integers/
例:
输入:a = 1, b = 2
输出:3
答:
class Solution {
public int getSum(int a, int b) {
while(b != 0)
{
int t = (a & b) << 1;
a = a ^ b;
b = t;
}
return a;
}
}