题目连接 https://leetcode-cn.com/problems/container-with-most-water/
Solution code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class Solution {
public int maxArea(int[] height) {
int max = 0;
if(height == null || height.length == 0) {
return max;
}
int left = 0;
int right = height.length - 1;
while(left < right) {
max = height[left] <= height[right] ?
Math.max((right - left) * height[left++], max) :
Math.max((right - left) * height[right--], max);
}
return max;
}
}