盛最多水的容器:

Leetcode 中等六 盛最多水的容器

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

 

相关文章:

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