Swap A and B without third variable
How to swap A and B without third variable?
Wrong solution:
a = 5, b = 7 a += b // (12) b = a - b // (12 - 7 = 5) a = a - b // (12 - 5 = 7)
Note:
You can also face the Integer overflow issue:
https://rosettacode.org/wiki/Integer_overflow
Solution:
a = 5, b = 7 a = a ^ b // (5 ^ 7 = 2) b = a ^ b // (2 ^ 7 = 5) a = a ^ b // (2 ^ 5 = 7)