Skip to content

Commit

Permalink
new solution
Browse files Browse the repository at this point in the history
  • Loading branch information
nandha46 committed Aug 19, 2024
1 parent 4520b46 commit 1b5a3eb
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Top Interview Questions/Array/Move Zeroes/Solution.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

class Solution {

/**
* @param Integer[] $nums
* @return NULL
*/
function moveZeroes(&$nums) {
if (count($nums) == 1){

} else {
$moved = 0;
for ($i = 0; $i < count($nums); $i++ ){
echo $i;
if (count($nums) - $i - 1 == $moved){
break;
}
if ($nums[$i] == 0){
array_splice($nums, $i, 1);
$nums[] = 0;
$moved++;
}
}
}
}

}
$nums = array(1,0,0,3,12);
$obj = new Solution();
$obj->moveZeroes($nums);
print_r($nums);
print_r(array(1,3,12,0,0));

?>

0 comments on commit 1b5a3eb

Please sign in to comment.