Created
January 17, 2016 05:36
-
-
Save rafaelbernard/ef8a766b24ee3abedf06 to your computer and use it in GitHub Desktop.
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 | |
// you can write to stdout for debugging purposes, e.g. | |
// print "this is a debug message\n"; | |
function solution($A) { | |
// write your code in PHP5.5 | |
$A = array_unique($A); | |
$count = count($A); | |
if ($count < 1) return 1; | |
$end = $count + 1; | |
$ordered = range(1, $end); | |
$flip_A = array_flip($A); | |
//print_r($fliped_A); | |
$flip_ordered = array_flip($ordered); | |
//print_r($flipper_ordered); | |
//$diff = array_diff($ordered, $A); | |
$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