Container with most water
Given n non-negative integers A1, A2, ..., an, where each represents a point at Coordi Nate (i, ai). N Vertical Lines is drawn such that the the both endpoints of line I am at (i, ai) and ( i, 0). Find lines, which together with X-axis forms a container, such that the container contains the most water.
Note:you may not slant the container.
https://leetcode.com/problems/container-with-most-water/
First saw trapping Rain water from similar problems find this way, confused for a long time.
is to choose 2 partitions, the partition between the non-occupied volume.
Double-pointer water problem.
1 /**2 * @param {number[]} height3 * @return {number}4 */5 varMaxarea =function(height) {6 vari = 0, j = height.length-1, max = 0, Curr;7 while(I <j) {8Curr = Math.min (Height[i], height[j]) * (J-i);9 if(Curr >max) {TenMax =Curr; One } AHeight[i] < Height[j]? i++: j--; - } - returnMax; the};
[Leetcode] [JavaScript] Container with most water