This question is part of NeetCode150 series.
Problem Description
Given two integers a and b, return the sum of the two integers without using the operators + and -.
Solution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Solution {
public int getSum(int a, int b) {
while(b != 0){
int temp = a&b;
a = a ^ b;
b = temp<<1;
}
return a;
}
}