Open Zheaoli opened 2 years ago
/*
* @lc app=leetcode id=11 lang=typescript
*
* [11] Container With Most Water
*/
// @lc code=start
function maxArea(height: number[]): number {
let ans = 0;
let start = 0;
let end = height.length - 1;
while (start < end) {
const size = (end - start) * Math.min(height[start], height[end]);
ans = Math.max(ans, size);
if (height[start] < height[end]) {
start++;
} else if (height[start] > height[end]) {
end--;
} else {
start++;
// it is the same if you end-- here
}
}
return ans;
};
// @lc code=end
微信id: 弘树 来自 vscode 插件
2022-09-13