```
class Solution {
public:
int missingNumber(vector<int>& N) {
int xors[] = {N.size(), 1, N.size() + 1, 0};
return xors[N.size() % 4] ^ accumulate(N.begin(), N.end(), 0, bit_xor<int>());
}
};
```

// xor for numbers from range [0, N] inclusive is

N if N%4 == 0

1 if N%4 == 1

N+1 if N%4 == 2

0 if N%4 == 3

credit: stackoverflow http://stackoverflow.com/questions/10670379/find-xor-of-all-numbers-in-a-given-range