what if two elements are not next to each other. would it work? On Oct 20, 8:19 am, "juver++" <avpostni...@gmail.com> wrote: > 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 <anshika.sp...@gmail.com> 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 algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.