leecode

代码:

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]);
    }
}

相关文章:

  • 2021-06-23
  • 2022-01-26
  • 2021-10-06
  • 2022-02-12
  • 2022-01-24
  • 2021-10-31
  • 2021-10-23
  • 2022-12-23
猜你喜欢
  • 2021-10-10
  • 2021-07-20
  • 2021-05-31
  • 2021-04-25
  • 2021-07-16
  • 2021-11-08
  • 2021-12-09
相关资源
相似解决方案