盛最多水的容器:
php:
52ms。双指针法。短板效应,所以移动小的值。
class Solution {
/**
* @param Integer[] $height
* @return Integer
*/
function maxArea($height) {
$maxArea = -1;
$end = count($height)-1;
$start = 0;
while($end > $start){
$maxArea = max(min($height[$start],$height[$end])*($end-$start),$maxArea);
$height[$start]<$height[$end] ? $start++ : $end--;
}
return $maxArea;
}
}