美文网首页
Container With Most Water

Container With Most Water

作者: 瞬铭 | 来源:发表于2019-02-26 13:59 被阅读0次

Container With Most Water

https://leetcode.com/problems/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

相关文章

网友评论

      本文标题:Container With Most Water

      本文链接:https://www.haomeiwen.com/subject/nnhayqtx.html