andybeak
8/14/2017 - 10:22 AM

Find the number in a list of integers that does not have a partner

Find the number in a list of integers that does not have a partner

<?php

$list = [1,2,3,4,5,2,3,4,5];

$total = 0;

foreach ($list as $cursor) {
  // note this is the binary xor operator, not the logical xor
  $total = $total ^ $cursor;
}

echo $total . PHP_EOL;  // 1