Created
March 14, 2016 09:15
-
-
Save gpfiel/20cfec389b206a838a68 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 | |
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]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i`ve done a better solution in relation of performance.