第二十二天:力扣第11题,盛最多水的容器
地址:leetcode-cn.com/problems/co…
思路:双指针,从左右往中遍历,返回最大值即可。
var maxArea = function(height) {
let res = 0;
for(let i = 0,j = height.length - 1; i < j;)
{
res = Math.max(Math.min(height[i],height[j])*(j-i) , res);
height[i] < height[j] ? i++ : j--;
}
return res;
};
执行用时:92 ms, 在所有 JavaScript 提交中击败了63.25%的用户
内存消耗:41.4 MB, 在所有 JavaScript 提交中击败了5.02%的用户