代码:
class Solution { /** * @param Integer[] $height * @return Integer */ function maxArea($height) { $len = count($height); $indexLen = $len - 1; $maxContainer = 0; for($i = 0,$j = $indexLen;$i < $j;){ $n1 = [$i,$height[$i]]; $n2 = [$j,$height[$j]]; $container = $this->getContainer($n1,$n2); if($container > $maxContainer){ $maxContainer = $container; } $height[$i] <= $height[$j] ? $i++ : $j --; } return $maxContainer; } function getContainer($n1,$n2){ return ($n2[0] - $n1[0]) * min($n1[1],$n2[1]); } }