function quick($a) {
if (count($a) < 2) return $a;
$l = [];
$r = [];
$pivot = $a[0];
foreach ($a as $val) {
if ($val > $pivot) {
$r[] = $val;
} else {
$l[] = $val;
}
}
return array_merge(quick($l), [$pivot], quick($r));
}
print_r(quick($a));
我收到此错误:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 72 bytes) in /Applications/XAMPP/xamppfiles/htdocs/sort.php on line 46
第 46 行是$l[] = $val;