3 ms·
You don't need to use xor, unless you are trying to be clever or have a number representation already in bits: n(n+1)/2 - sum(array) is your answer and is O(n);
by lsiebert 11y ago
You don't need to use xor, unless you are trying to be clever or have a number representation already in bits: n(n+1)/2 - sum(array) is your answer and is O(n);
- fsk 11y agoxor is the solution that uses the least storage I heard a variation of that question that began "using the least possible storage space...", with the goal being to find the xor solution. The arithmetic solution also has problems when you overflow an integer, although that matters more if your CPU has 16 bit ints.