this entry collects the solution files i have for asteroid collission. i may expand it with a fuller write-up later, but the implementation files are already here.
available solution files
- PHP
asteroid-collission/asteroid-collission.php
notes and solution files for asteroid collission.
this entry collects the solution files i have for asteroid collission. i may expand it with a fuller write-up later, but the implementation files are already here.
asteroid-collission/asteroid-collission.phpclass Solution {
function asteroidCollision($asteroids) {
$stack = [];
foreach ($asteroids as $asteroid) {
$crush = class="syntax-number">1;
while ($crush > class="syntax-number">0 && $asteroid < class="syntax-number">0 && !empty($stack) && end($stack) > class="syntax-number">0) {
$crush = -class="syntax-number">1 * $asteroid <=> end($stack);
if ($crush >= class="syntax-number">0) {
array_pop($stack);
}
}
if ($crush > class="syntax-number">0) {
array_push($stack, $asteroid);
}
}
return $stack;
}
}