public class Solution {
public int maxArea(int[] height) {
int max = 0;
int left = 0;
int right = height.length-1;
while (left<right){
max = Math.max(max, Math.min(height[left], height[right])*(right - left));
if (height[left]<height[right]){
int k = left;
while (k<right && height[left] >= height[k]){
k++;
}
left = k;
}else {
int k = right;
while(k > left && height[right] >= height[k]){
k--;
}
right = k;
}
}
return max;
}
}
Container With Most Water
最新推荐文章于 2019-11-06 10:22:53 发布