java: add «11. Container With Most Water»

Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2024-08-12 21:50:29 +02:00
parent 66f8d84892
commit 23cd6ac490
Signed by: mfocko
SSH key fingerprint: SHA256:icm0fIOSJUpy5+1x23sfr+hLtF9UhY8VpMC7H4WFJP8

View file

@ -0,0 +1,18 @@
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;
}
}