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
相关推荐
zhanghaha131420 分钟前
Python语言基础:4_数据类型转换atunet23 分钟前
从算法优化到系统加速的多层级思考7Devin~Y1 小时前
互联网大厂Java面试实战:Spring Boot、MyBatis、Redis、Kafka、JWT、Spring Cloud 与 AI 场景追问Navigator_Z1 小时前
LeetCode //C - 1156. Swap For Longest Repeated Character SubstringReart1 小时前
Leetcode 1143.最长公共子序列(720)花生了什么事o1 小时前
DDD:领域驱动设计的初步认识无相求码1 小时前
const vs #define:C语言常量定义的差异BGK1123581 小时前
基于qemu_v8+optee 4.00 平台构建 ca/ta先吃饱再说2 小时前
LeetCode 226. 翻转二叉树何中应2 小时前
Spring Boot整合Doris