This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$list = array(3,4,2,5,6,7,8,2,5,1,4,4,6); | |
function maximum($list) | |
{ | |
$len = count($list); | |
$maximum = $list[0]; | |
for ($i = 1; $i < $len; $i++) { | |
if ($maximum < $list[$i]) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$list = array(3,4,2,5,6,7,8,2,5,1,4,4,6); | |
function min_and_max($list) | |
{ | |
$len = count($list); | |
$minimum = $maximum = $list[0]; | |
for ($i = 1; $i < $len; $i++) { | |
if ($minimum > $list[$i]) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function min_and_max($list) | |
{ | |
$len = count($list); | |
$minimum = $maximum = $list[0]; | |
// adding a centinel | |
if ($len % 2 == 0) { | |
$list[] = $list[0]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function min_and_max($list) | |
{ | |
$len = count($list); | |
$minimum = $maximum = $list[0]; | |
$start = 1; | |
if (!($len & 1)) { | |
$start = 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[a, b] = [b, a] |
OlderNewer