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

猜你喜欢

转载自blog.csdn.net/qq_36688622/article/details/89341177