Skip to content

Added solution in PHP language - #76

Open
sarvar-akbarov wants to merge 1 commit into
Skill-Development-Marathon:mainfrom
sarvar-akbarov:patch-21
Open

Added solution in PHP language#76
sarvar-akbarov wants to merge 1 commit into
Skill-Development-Marathon:mainfrom
sarvar-akbarov:patch-21

Conversation

@sarvar-akbarov

Copy link
Copy Markdown
class Solution {

    /**
     * @param Integer[] $nums
     * @param Integer $pivot
     * @return Integer[]
     */
    function pivotArray($nums, $pivot) {
        $result = [];

        $countPivots = 0;

        foreach($nums as $key => $num){
            if($num < $pivot){
                $result[] = $num;
                unset($nums[$key]);
            }elseif($num == $pivot){
                $countPivots++;
                unset($nums[$key]);
            }
        }

        while($countPivots--){
            $result[] = $pivot;
        }

        foreach($nums as $num){
            $result[] = $num;
        }

        return $result;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant