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
相关推荐
RInk7oBjo几秒前
spring boot3--自动配置与手动配置最初的↘那颗心3 分钟前
LangChain4j核心能力:AiService、Prompt注解与结构化输出实战lixia0417mul25 分钟前
简单的RAG知识库问答云烟成雨TD8 分钟前
Spring AI 1.x 系列【25】结构化输出案例演示鱼鳞_8 分钟前
Java学习笔记_Day23(HashMap)hua_ban_yu8 分钟前
新版本 idea 如何设置热部署穿条秋裤到处跑10 分钟前
每日一道leetcode(2026.04.07):模拟行走机器人 IIodng13 分钟前
拉取最新代码报错修复说明sheeta199813 分钟前
LeetCode 每日一题笔记 日期:2026.04.07 题目:2069.模拟行走机器人二