Firstly, see the Problem Source
Secondly, I will give my code below.
public class Solution {
public int maxArea(int[] height) {
int width = height.length;
int max = 0;
int left = 0, right = width - 1;
while (left < right){
max = Math.max(max, (right - left)*(Math.min(height[left], height[right])));
if (height[left] > height[right]) right--;
else left++;
}
return max;
}
}
My Summary
The main idea is using two indicators, left and right. MOVE the indicator whose value is smaller until they encounter.