leetcode - Container With Most Water

来源:互联网 发布:手机语音聊天软件 编辑:程序博客网 时间:2024/06/08 15:03
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.


Note: You may not slant the container.


解析: i,j 两点之间,假设i点高度小于j点高度,那他们两点间的容量c=(j - i )* i的高度 ,任意i ,j 之间的一点k 与 i 点组成的水桶容量一定小于i,j之间的容量c。所以i点 与其他点之间的容量就不用算了。


0 0
原创粉丝点击