Description Title
without using operators + and - calculates two integers a, b sum.
Example 1:
Input: a = 1, b = 2
Output: 3
Example 2:
Input: a = -2, b = 3
Output: 1
Code
public class Solution {
public int getSum(int a,int b){
int sum,carry;
sum = a^b;
carry = (a&b)<<1;//专门记录进位
if(carry!=0){
return getSum(sum,carry);
}
return sum;
}
}
Performance