Created
November 17, 2018 07:09
-
-
Save anujsinghwd/34056c0d14d63cba13456ed5a4106d0d to your computer and use it in GitHub Desktop.
Sort an array of 0s, 1s and 2s
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 | |
$arr = array(0,2,1,2,0); | |
$n = count($arr); | |
$count = array_count_values($arr); | |
$new_arr; | |
for($j=0;$j<=2;$j++){ | |
for($i=0;$i<$count[$j];$i++){ | |
$new_arr[] = $j; | |
} | |
} | |
print_r($new_arr); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment