Zheaoli / do-something-right

MIT License
37 stars 3 forks source link

2022-09-13 #359

Open Zheaoli opened 2 years ago

Zheaoli commented 2 years ago

2022-09-13

Dapeus commented 2 years ago

image

gongpeione commented 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 插件