Givennnon-negative integersa1,a2, ...,an, where each represents a point at coordinate (i,ai).nvertical lines are drawn such that the two endpoints of lineiis 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 andnis at least 2.
分析:
題目大意是要找出組成容器的最大容量徘禁,容量的大小計(jì)算公式: area = (H[j]-H[i]) * min(H[i], H[j])??? (i<=j)
方法:容量大小取決于兩根線的距離[X]和兩根線當(dāng)中小的那個(gè)min炕矮。
可以考慮將 [X] 初始化為最大值,然后不斷遞減寥闪,當(dāng)固定[X]時(shí)桶雀,min越大唠叛,容量也越大