当前位置:网站首页>Topic26——11. Container with the most water
Topic26——11. Container with the most water
2022-06-09 05:44:00 【_ Cabbage_】
subject : Given a length of n Array of integers for height . Yes n Vertical line , The first i The two ends of the line are (i, 0) and (i, height[i]) .
Find two of them , Make them x A container of shafts can hold the most water .
Return the maximum amount of water that the container can store .
explain : You can't tilt the container .
Example 1:

Input :[1,8,6,2,5,4,8,3,7]
Output :49
explain : The vertical line in the figure represents the input array [1,8,6,2,5,4,8,3,7]. In this case , The container can hold water ( In blue ) The maximum value of is 49.
Example 2:
Input :height = [1,1]
Output :1
Tips :
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;
}
}
边栏推荐
- Youshimu V8 projector opens the "vision" field of high fresh
- Ecmascript6.0 Basics
- Encapsulation of common methods in projects
- @Differences between jsonformat and @datetimeformat
- 计网中的一些概念
- Basic knowledge of deep learning: face based common expression recognition (1)
- ThreadLocal parsing
- 代码签名证书的时间戳验证码签名方法
- Gstreamer应用开发实战指南(二)
- Local redis cluster setup
猜你喜欢

Common interview questions

Alibaba cloud AI training camp - machine learning 3:lightgbm

Good hazelnut comes from Liaoyang!

【IT】福昕pdf保持工具选择

What information does the SSL certificate contain?

Yolov5-6.0系列 | yolov5的模型网络构建

reids 缓存与数据库数据不一致、缓存过期删除问题

Alibaba cloud AI training camp -sql foundation 2: query and sorting

Wamp environment setup (apache+mysql+php)

Youshimu V8 projector opens the "vision" field of high fresh
随机推荐
synchronized 详细解析
[it] Fuxin PDF Keeping Tool Selection
C语言编写计算文件CRC的小程序
Unbutu 安装FFmpeg的两种方法
XML modeling
Interpretation of join method in thread
Fundamentals of deep learning: face based common expression recognition (2) - data acquisition and collation
Basic knowledge of deep learning: face based common expression recognition (1)
CEF 拦截URL,重定向新的网址
Wechat applet wx Getlocation location error information summary
Alibaba cloud AI training camp - machine learning 2:xgboost
@Differences between jsonformat and @datetimeformat
MySQL one master multi slave configuration centos7 pro test
Alibaba cloud AI training camp - SQL basics 3: complex query methods - views, subqueries, functions, etc
Leetcode 1037. Effective boomerang
Web page capture software
Good hazelnut comes from Liaoyang!
Heap and priority queues
groupby函数详解
matlab----多项式、函数