Skip to content

盛最多水的容器

🕒 Published at:

LeetCode 第11题

typescript
function maxArea(height: number[]): number {
    let left = 0
    let right = height.length - 1
    let max = 0
    while(left < right){
        let width = right - left
        let heights = Math.min(height[left], height[right])
        max = Math.max(max, width * heights)
        if(height[left] < height[right]){
            left++
        }else{
            right--
        }
    }
    return max
};