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 and 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.
Two pointers, similar to trapping Rain water.
A pointer with a small value is approximated to the middle.
The complexity of O (n).
classSolution { Public: intMaxarea (vector<int> &height) { if(Height.empty () | | height.size () = =1) return 0; intresult =0; intleft =0; intright = Height.size ()-1; intLeftwall =Height[left]; intRightwall =Height[right]; while(Left <Right ) {Result= Max (result, Min (Leftwall, rightwall) * (right-Left )); if(Leftwall <=Rightwall) { Left++; Leftwall=Height[left]; } Else{ Right--; Rightwall=Height[right]; } } returnresult; }};
"Leetcode" Container with the most water