You can use the "xor" operation for the whole array. Each pair of numbers will cancel each other, leaving you with the desired value.
int get_orphan(int const * a, int len) { int value = 0; for (int i = 0; i < len; ++i) value ^= a[i];
avakar
source share