Given two integers a and b, return their sum without using the + or - operators. Use bitwise operations (AND, OR, XOR, shifts) to simulate addition with carrying instead.
Input / output
a: integer, b: integerinteger, equal to a + bExamples
a = 1, b = 2 returns 3.a = 2, b = 3 returns 5.a = -2, b = 3 returns 1.Constraints
-1,000 <= a, b <= 1,000Follow-up
Can you explain why a XOR b gives the sum without carries, and (a AND b) << 1 gives exactly the carries that must be added back in, repeating until there is no carry left?