11.盛最多水的容器

2020-03-04  本文已影响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
}
上一篇下一篇

猜你喜欢

热点阅读