1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-14 01:49:41 +01:00
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;
}
}