美文网首页
11. Container With Most Water

11. Container With Most Water

作者: jluemmmm | 来源:发表于2021-01-21 12:22 被阅读0次
  • Runtime: 84 ms, faster than 75.66%
  • Memory Usage: 41.6 MB, less than 13.80%

容器中可以最大装水数,双指针法进行实现

/**
 * @param {number[]} height
 * @return {number}
 */
var maxArea = function(height) {
    let start = 0
    let end = height.length - 1
    let cur = 0
    let max = 0
    while (start < end) {
        if(height[start] > height[end]) {
            cur = (end - start) * height[end]
            end--
        } else {
            cur = (end - start) * height[start]
            start++
        }
        if(cur > max) max = cur
    }
    return max
};

相关文章

网友评论

      本文标题:11. Container With Most Water

      本文链接:https://www.haomeiwen.com/subject/vnirzktx.html