Suggested approach by Anirvana doesn't work for this problem. It's ok if array contain numbers that are repeated twice except one element and we need to find it. For this version solution is simple - iterate over elements and find it's XOR value, so result = a[0] XOR a[1] ... XOR a[n - 1]. Resulted value is an element which presented only once in the array. It works because of a property of XOR operation - a XOR a = 0 (so repeated twice pairs disappeared).
On 20 окт, 14:44, Asquare <[email protected]> wrote: > @Anirvana - In context to the XOR method u suggested, could u plz > explain why does it so happen.. ?? -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
