当前位置:网站首页>Topic26——11. 盛最多水的容器
Topic26——11. 盛最多水的容器
2022-06-09 05:38:00 【_卷心菜_】
题目:给定一个长度为 n 的整数数组 height 。有 n 条垂线,第 i 条线的两个端点是 (i, 0) 和 (i, height[i]) 。
找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水。
返回容器可以储存的最大水量。
说明:你不能倾斜容器。
示例 1:

输入:[1,8,6,2,5,4,8,3,7]
输出:49
解释:图中垂直线代表输入数组 [1,8,6,2,5,4,8,3,7]。在此情况下,容器能够容纳水(表示为蓝色部分)的最大值为 49。
示例 2:
输入:height = [1,1]
输出:1
提示:
n == height.length
2 <= n <= 105
0 <= height[i] <= 104
class Solution {
public int maxArea(int[] height) {
int[] memo = new int[height.length];
Arrays.fill(memo, 0);
int result = 0;
for(int i = 1; i < height.length; i++) {
for(int j = 0; j < i; j++) {
if(height[j] > height[i]) {
memo[i] = Math.max(memo[i], height[i] * (i - j));
break;
}
memo[i] = Math.max(memo[i], Math.min(height[j], height[i]) * (i - j));
}
result = Math.max(result, memo[i]);
}
return result;
}
}
边栏推荐
- Alibaba cloud AI training camp - machine learning 3:lightgbm
- Gstreamer应用开发实战指南(三)
- 数据血缘用例与扩展实践
- [it] Foxit PDF retention tool selection
- Redis cache avalanche, penetration and breakdown
- 对pyqt5和SQL Server数据库进行连接
- Source code analysis of cyclicbarrier in AQS
- Heqibao's trip to Chongqing ~
- Yolov5-6.0 series | yolov5 model network construction
- Yolov5-6.0系列 | yolov5的模块设计
猜你喜欢

Morsel driven parallelism: a NUMA aware parallel query execution framework

Wamp environment setup (apache+mysql+php)

Gstreamer应用开发实战指南(四)

Apache devlake code base guide

Several implementation methods of redis distributed lock

Painstakingly wrote a detailed MySQL tutorial of 24K words in three days, three nights

SET DECIMAL_ V2=false and UDF error: cannot divide decimal by zero and incompatible return types decimal
groupby函数详解

WAMP环境搭建(apache+mysql+php)

In latex, \cdots is followed by a sentence. What's wrong with the format of the following sentence.
随机推荐
debian11安装nfs server后固定端口号以便设置防火墙
Xtrabackup backup and recovery
Morsel driven parallelism: a NUMA aware parallel query execution framework
Quelles sont les informations contenues dans le certificat SSL?
reids 缓存与数据库数据不一致、缓存过期删除问题
pytorch DDP加速之gradient accumulation设置
Stack
XML建模
validate-npm-package-name
AQS 之 Semaphore 源码分析
Record an opensips DNS problem
AspNetPager combines stored procedure paging to speed up access
Enter two positive integers m and N to find their maximum common divisor and minimum common multiple.
Seaweedfs client adapts to the higher version of seaweedfs service
2022年11月15日起,代码签名证书私钥均需存储在硬件加密模块中
对pyqt5和SQL Server数据库进行连接
Gstreamer应用开发实战指南(三)
Yolov5-6.0系列 | yolov5的模块设计
Article title
csv文件读取(v3&v5)