int ones = 0; int twos = 0; int not_threes, x; for (int i=0; i<n; ++i) { x = A[i]; twos |= ones & x; ones ^= x; not_threes = ~(ones & twos); ones &= not_threes; twos &= not_threes; }
Read full article from algorithm - Finding an element in an array where every element is repeated odd number of times (but more than single occurrence) and only one appears once - Stack Overflow
No comments:
Post a Comment