Public classSolution { Public intMaxarea (int[] height) { /*Test Instructions: There are n points in the two-dimensional coordinate system (I, AI), Ai >= 0, from (I, AI) to (i, 0) the vertical line, a total of n vertical lines. Find two vertical lines so that they make up the largest area of the rectangle and the height of the rectangle depends on the shortest vertical line. Idea: Greedy starts scanning from the top and bottom two subscript head and trail, using a variable Maxarea to maintain the current largest rectangular area. If the vertical line that the head points to is shorter than the trail, move the head to the right or the left trail calculates the area, updating the Maxarea complexity: Time O (n), Space O (1)*/ if(HEIGHT.LENGTH<2)return0; intLeft=0; intRight=height.length-1; intRes=0; while(left<Right ) {Res=math.max (Res,math.min (Height[left],height[right]) * (right-Left )); if(height[left]<Height[right]) { Left++; }Else Right--; } returnRes; }}
[Leedcode 11] Container with most water