Container With Most Water
暴力求解
class Solution {
/**
* @param Integer[] $height
* @return Integer
*/
function maxArea($height) {
$max = 0;
foreach ($height as $i => $h) {
foreach ($height as $j => $k) {
if ($j <= $i) {
continue;
}
$x = $j - $i;
$y = min($h, $k);
$vol = $x * $y;
$max = $max < $vol ? $vol : $max;
}
}
return $max;
}
}
数学证明的最优解:https://blog.csdn.net/kid551/article/details/83094787
网友评论