示例 1:
输入: a = 1, b = 2 输出: 3 示例 2:
输入: a = -2, b = 3 输出: 1
class Solution {
public int getSum(int a, int b) {
while(b!=0){
int sum=a^b; //无进位相加;
b=(a&b)<<1; //有进位相加,左移;
a=sum;
}
return a;
}
}
class Solution {
public int getSum(int a, int b) {
return b== 0 ? a : getSum(a^b,(a&b)<<1);
}
}