805. Swap Two Numbers
Given two integers a and b, swap them in-place using only 2 variables (without using a temporary variable).
Can you solve it using:
- Arithmetic operations?
- Bitwise XOR?
Example 1:
Input: a = 5, b = 10
Output: a = 10, b = 5
Example 2:
Input: a = -100, b = -200
Output: a = -200, b = -100
Now Your Turn!
Pick the correct output for the given inputInput: a = 0, b = 99
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
109 <= a, b <= 109