Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is conceptually almost the same as summing over all entries and comparing to the sum of all numbers in [1, n], except that the latter can be done more efficiently because that sum is simply n*(n+1)/2.

There are in fact legit use cases for XOR to speed things up or make algorithms simpler, but this is not the case here IMHO.



XOR handles overflow better than the summing mechanism.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: