Created
August 14, 2017 10:22
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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