Sum of Two Integers
Return a+b without using addition or subtraction operators in the implementation. Use 32-bit two-complement bit operations.
Example 1
a = 5
b = -32Explanation
Combining positive 5 and negative -3 gives 2.
Example 2
a = -7
b = -8-15Explanation
Two negative operands give -15; signed conversion must preserve its sign.
Example 3
a = 0
b = 00Explanation
Zero operands create neither a sum bit nor a carry.
Example 4
a = 999
b = 11000Explanation
Carry propagation through the low bits turns 999 and 1 into 1000.
Constraints
- -1000 <= a,b <= 1000
Function contract
getSumArguments: json, jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
5-3