欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

求盛最多水的容器

程序员文章站 2024-02-01 15:52:28
/** * @param {number[]} height * @return {number} */ var maxArea = function(height) { let maxarea = 0 for(let i=0;i=0; j--){ maxarea = Math.max(maxare... ......

求盛最多水的容器

 

 

/**
 * @param {number[]} height
 * @return {number}
 */
var maxArea = function(height) {
    let maxarea = 0
    for(let i=0;i<height.length; i++){
        for(let j=height.length-1; j>=0; j--){
            maxarea = Math.max(maxarea,Math.min(height[i],height[j])*((i-j)>0?(i-j):(j-i)))
        }
    }
    return maxarea
};