美文网首页
11.盛最多水的容器

11.盛最多水的容器

作者: 寂灭天骄小童鞋 | 来源:发表于2020-03-04 17:09 被阅读0次

https://leetcode-cn.com/problems/container-with-most-water/

func maxArea(_ height: [Int]) -> Int {
    if height.count <= 0 {return 0}
    var left = 0
    var right = height.count - 1
    var result = 0
    while left < right {
        result = max(result, min(height[left], height[right]) * (right - left))
        if height[left] < height[right] {
            left = left + 1
        } else {
            right = right - 1
        }
    }
    return result
}

相关文章

网友评论

      本文标题:11.盛最多水的容器

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