LeetCode 1089: Duplicate Zeros

May. 2, 2021

LeetCode 1089: Duplicate Zeros solution in PHP.


  /**
    * @param Integer[] $arr
    * @return NULL
    */
    function duplicateZeros( & $arr) {
        $len = count($arr);
        for ($i=0; $i   < $len; $i++) {
            if (0 === $arr[$i]) {
                array_splice($arr, $i++, 0, 0);
            }
        }
        array_splice($arr, $len);
    }
}