/** * @param {number[]} height * @return {number} */ var maxArea = function (height) {
let max = 0; const length = height.length; let startIndex = 0; let endIndex = length - 1; while (startIndex < endIndex) { let len = endIndex - startIndex; let h = height[startIndex]; if (height[startIndex] > height[endIndex]) { h = height[endIndex]; endIndex--; } else { h = height[startIndex]; startIndex++; }
const sum = len * h; if (sum > max) { max = sum } }