Ad
  • Custom User Avatar

    First of all it is using logic gates. In this case, we are using the bitwise or.
    So:
    0 ^ 0 = 0
    0 ^ 1 = 1
    1 ^ 0 = 1
    1 ^ 1 = 0

    and for example if our array of numbers is [5, 3, 2, 5, 2].
    Now if we iterate through this array we can see that if we bitwise all the numbers we get the number that isnt repeated as the same number will cancel out each other and equal 0
    5 ^ 5 -> 1 0 1 ^ 1 0 1 = 0 0 0

    If they are the same value, they equal 0 and if they are different values they equal 1. despite weather or not the two values are 1's or 0's.

    Now when we iterate through the array
    1 0 1 ^ 0 1 1 = 1 1 0
    1 1 0 ^ 0 1 0 = 1 0 0
    1 0 0 ^ 1 0 1 = 0 0 1
    0 0 1 ^ 0 1 0 = 0 1 1 which is equal to 3.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    hey bro, can you explain this please , because I am a kind of lost