Files
leetcode/11.container-with-most-water.java
2025-10-30 14:47:22 +08:00

24 lines
471 B
Java

/*
* @lc app=leetcode id=11 lang=java
*
* [11] Container With Most Water
*/
// @lc code=start
class Solution {
public int maxArea(int[] height) {
int l = 0, r = height.length -1, max = 0;
while(l < r) {
max = Math.max(max, (r-l)*Math.min(height[l], height[r]));
if(height[l] < height[r]) {
l++;
} else {
r--;
}
}
return max;
}
}
// @lc code=end