Calculate the sum of two integersaandb, but you arenot allowedto use the operator+
and-
.
class Solution {
public int getSum(int a, int b) {
if (b == 0)
return a;
int sum = a ^ b;
int carry = (a & b) << 1;
return getSum(sum, carry);
}
}