class Solution {
public int maxArea(int[] height) {
int ans = 0;
int left = 0;
int right = height.length - 1;
while (left < right) {
ans = Math.max(ans, getArea(height, left, right));
if (height[left] < height[right]) {
left++;
} else {
right--;
}
}
return ans;
}
private int getArea(int[] nums, int left, int right) {
return (right - left) * Math.min(nums[left], nums[right]);
}
}
力扣11.盛水最多的容器
听风客12024-09-03 13:20
相关推荐
王九思1 分钟前
Java 内存分析工具 MATAlenTech8 分钟前
197. 上升的温度 - 力扣(LeetCode)浅水壁虎12 分钟前
任务调度——XXLJOB2(调度中心)青火coding15 分钟前
SOFAServerless架构的意义夕除25 分钟前
java--2橘颂TA36 分钟前
【Linux 网络】TCP 拥塞控制与异常处理:从原理到实践的深度剖析源码获取_wx:Fegn089541 分钟前
计算机毕业设计|基于springboot + vue景区管理系统(源码+数据库+文档)李少兄1 小时前
Git 忽略文件机制:.gitignore 与 .git/info/exclude☀Mark_LY1 小时前
个人数据同步es小工具组合缺一1 小时前
开发 Java MCP 就像写 Controller 一样简单,还支持 Java 8