Re:Ask HN: What are your favorite code problems to give whil...
by siscia on Saturday June 13, 2015 @06:31AM
(#9710561)
How do you flip two variable without a third one ?
[ Parent
| on HN ]
Re:Ask HN: What are your favorite code problems to give whil...
by pdiddy on Saturday June 13, 2015 @08:36AM
(#9710816)
Another way is to just use subtraction:
x = x + y
y = x - y
x = x - y
I originally learned about this while preparing for some interviews.The funny thing, I find, is that in Python you can simply do this:
x, y = 5, 10
x, y = y, x
I was asked this question in an interview and I responded that you can do this. His response: "Python is weird."