feat: 2025-10-30打卡(接雨水)
This commit is contained in:
23
11.container-with-most-water.java
Normal file
23
11.container-with-most-water.java
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* @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
|
||||
|
||||
Reference in New Issue
Block a user