An array A[1...n] contains all the integers from 0 to n except for one number which is missing. In this problem, we cannot access an entire integer in A with a single operation. The elements of A are represented in binary, and the only operation we can use to access them is "fetch the jth bit of A[i]", which takes constant time. Write code to find the missing integer. Can you do it in O(n) time?
基本思路是D & C :
参考答案:
C++:https://github.com/writecoffee/career_cup_iteration/blob/improved/5.7.cpp
Java:https://gist.github.com/xuyirio/3156330
超牛逼的XOR位运算,目前还没完全看懂:https://github.com/0x7ffff/Career-Cup-archive/blob/master/5/7.c
我的代码: