题解 | #盛水最多的容器#
盛水最多的容器
https://www.nowcoder.com/practice/3d8d6a8e516e4633a2244d2934e5aa47
public class Solution {
public int maxArea(int[] bar) {
int n = bar.length;
int iL = 0;
int iR = n - 1;
int result = 0;
//本质上是双指针中的同向不同步方法,用于解决最值问题;
while (iL < iR) {
int area = Math.min(bar[iL], bar[iR]) * (iR - iL);
result = Math.max(result, area);
if (bar[iL] < bar[iR])
iL++;
else
iR--;
}
return result;
}
}