您的位置:首页 > 大数据 > 人工智能

Container With Most Water

2015-07-02 15:42 363 查看
public class Solution {
public int maxArea(int[] height) {
if (height == null || height.length < 2) {
return 0;
}
int left = 0;
int right = height.length - 1;
int maxVolume = Math.min(height[left], height[right]) * (right - left);
while (left < right) {
if (height[left] < height[right]) {
left++;
} else {
right--;
}
maxVolume = Math.max(maxVolume, Math.min(height[left], height[right]) * (right - left));
}
return maxVolume;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Array Two Pointers