11. 盛最多水的容器
https://leetcode-cn.com/problems/container-with-most-water/
解法一:暴力(超时)
解法二:双指针
具体证明见https://leetcode.com/problems/container-with-most-water/solution/
l=0,r=n-1,比较两处高度,较小的往中间移。
可以理解为贪心?height[l]<height[r]
时,若移动较矮的l,虽然宽度变窄,但是可能得到一个更高的从而弥补;若移动较高的r,不一定得到更高的,从而面积减小。
最后更新于