371. Sum of Two Integers
Input:
a = 1, b = 2
Output: 3Input:
a = -2, b = 3
Output: 1class Solution {
public:
int getSum(int a, int b) {
return b == 0? a: getSum(a^b, (a&b) << 1);
}
};Last updated
Was this helpful?
Input:
a = 1, b = 2
Output: 3Input:
a = -2, b = 3
Output: 1class Solution {
public:
int getSum(int a, int b) {
return b == 0? a: getSum(a^b, (a&b) << 1);
}
};Last updated
Was this helpful?
Was this helpful?