11. 盛最多水的容器

func maxArea(height []int) int {

    res := 0
    i := 0
    j := len(height)-1
    for i<j {
        dif := j-i
        if height[i]<height[j] {
            res = max(res, dif * height[i])
            i++
        } else {
            res = max(res, dif * height[j])
            j--
        }
    }
    return res
}

func max(a,b int) int {
    if a>b {
        return a
    }
    return b
}
posted @ 2024-06-14 09:58  gdut17_2  阅读(19)  评论(0)    收藏  举报