Book: Cracking the Coding Interview
Question: 17.1 (page 163)
Write a function to swap [two numbers] in place (that is, without temporary variables)
Solution: Simple arithmetic trick. Also could be done using XOR (not sure if works with negative values, though.).
No comments:
Post a Comment