LeetCode/java/container-with-most-water.java
Matej Focko 23cd6ac490
java: add «11. Container With Most Water»
Signed-off-by: Matej Focko <me@mfocko.xyz>
2024-08-12 21:50:29 +02:00

18 lines
333 B
Java

class Solution {
public int maxArea(int[] height) {
int foundMax = 0;
int l = 0, r = height.length - 1;
while (l < r) {
foundMax = Math.max(foundMax, (r - l) * Math.min(height[l], height[r]));
if (height[l] < height[r]) {
++l;
} else {
--r;
}
}
return foundMax;
}
}