Topic:
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.
Links: http://leetcode.com/problems/container-with-most-water/
The puzzle: The pointers, each moving to a smaller pointer. Time Complexity-o (n), Space complexity-o (1)
Public classSolution { Public intMaxarea (list<integer>height) { if(Height = =NULL|| Height.size () < 2) return0; intMax = 0, left = 0, right = height.size ()-1; while(Left <Right ) { intCurarea = Math.min (Height.get (left), Height.get (right)) * (Right-Left ); Max=Math.max (max, Curarea); if(Height.get (left) <Height.get (right))++; Else Right--; } returnMax; }}
Container with the most water