Sunny-117 / js-challenges

✨✨✨ Challenge your JavaScript programming limits step by step

Home Page:https://juejin.cn/column/7244788137410560055

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

盛最多水的容器

lzxjack opened this issue · comments

/**
 * @param {number[]} height
 * @return {number}
 */
var maxArea = function(height) {
    let left = 0; right = height.length - 1, max = 0;
    while(left < right){
        let temp = (right - left) * Math.min(height[left],height[right]) // 长x宽的值
        if(temp > max){
            max = temp
        }
        if(height[left] <= height[right]){ //留下长的那一边
            left++
        }
        else{
            right--
        }
    }
    return max
};