以Y坐标长度作为木桶边界,以X坐标差为桶底,找出可装多少水。
思路:
前后遍历。
Runtime: 5 ms, faster than 95.28% of Java
class Solution {
public int maxArea(int[] height) {
int res = 0;
int beg = 0;
int end = height.length - 1;
int temp = 0;
while (beg != end) {
temp = Math.min(height[beg], height[end]) * (end - beg);
res = temp > res ? temp : res;
if (height[beg] > height[end])
end--;
else
beg++;
}
return res;
}