Skip to content

Instantly share code, notes, and snippets.

@rafaelbernard
Last active January 17, 2016 04:33
Show Gist options
  • Save rafaelbernard/82e952b81b1992206835 to your computer and use it in GitHub Desktop.
Save rafaelbernard/82e952b81b1992206835 to your computer and use it in GitHub Desktop.
<?php
function solution($A) {
// write your code in PHP5.5
$count = count($A);
if ($count < 1) return 1;
$end = $count + 1;
$ordered = range(1, $end);
$flip_A = array_flip($A);
$flip_ordered = array_flip($ordered);
$diff = array_diff_key($flip_ordered, $flip_A);
if(count($diff) == 0) return 1;
$key_flip = current($diff);
$value = $ordered[$key_flip];
return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment