class Solution {
public int maxArea(int[] height) {
int max = 0;
int left = 0;
int right = height.length - 1;
if (height.length == 0 || height == null){
return max;
}
while(left < right){
if (height[left] < height[right]){
max = Math.max(max, height[left] * (right - left));
left++;
} else {
max = Math.max(max, height[right] * (right - left));
right--;
}
}
return max;
}
}
本文介绍了一种寻找能盛最多水的两个板的算法实现。通过双指针技巧,逐步移动较短的边界来优化搜索过程,实现了高效的解决方案。
708

被折叠的 条评论
为什么被折叠?



