Skip to content

Instantly share code, notes, and snippets.

@gpfiel
Created March 14, 2016 09:15
Show Gist options
  • Save gpfiel/20cfec389b206a838a68 to your computer and use it in GitHub Desktop.
Save gpfiel/20cfec389b206a838a68 to your computer and use it in GitHub Desktop.
<?php
function test($v, $arr1) {
$arr2 = [];
while(1){
$count1 = isset(array_count_values($arr1)[$v]) ? array_count_values($arr1)[$v] : 0;
$count2 = isset(array_count_values($arr2)[$v]) ? array_count_values($arr2)[$v] : 0;
if(count($arr1) == 0 || $count1 == count($arr2) - $count2) {
return count($arr1);
}
$arr2[] = array_shift($arr1);
}
}
echo test(5, [5,5,1,7,2,3,5]);
@gpfiel
Copy link
Author

gpfiel commented Mar 14, 2016

i`ve done a better solution in relation of performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment