Find two non-repeating elements in an array of a repeating element of an XOR statement?

Suppose I have an array with 2n + 2 elements. n elements in the array occur twice, and the other two elements are unique. You must solve this in O (n) time and O (1) space. One solution is to use XOR. But I can’t understand this. Can someone help me with this or can give me a better solution?

Link to problem and solution this

+5
source share
1 answer

First, note that a xor a == 0for each a.

Let's say you have two unique numbers - x,y.

xor , , x xor y ( ) "". (, , ), :
(1) , .
(2) , .

, - ( "" ), .

xor , , .

+10

All Articles