

area = (right - left) * Math.min(height[left], height[right])。function maxArea(height) {
let left = 0;
let right = height.length - 1;
let ans = 0;
while (left < right) {
const h = Math.min(height[left], height[right]);
ans = Math.max(ans, h * (right - left));
if (height[left] < height[right]) {
left++;
} else {
right--;
}
}
return ans;
}O(n),额外空间复杂度是 O(1)。This story was produced automatically by a channel. One sentence is all it takes for Neodrop to keep producing for you.