Skip to content

Instantly share code, notes, and snippets.

@andybeak
Created August 14, 2017 10:22
Show Gist options
  • Save andybeak/69c371e1e0924e21ea3aa651930baafd to your computer and use it in GitHub Desktop.
Save andybeak/69c371e1e0924e21ea3aa651930baafd to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment