当前位置:网站首页>2021-4-7-find the maximum water holding capacity
2021-4-7-find the maximum water holding capacity
2022-07-27 12:18:00 【Anethole job】
Container for the most water
Here you are. n Nonnegative integers a1,a2,…,an, Each number represents a point in the coordinate (i, ai) . Draw in coordinates n Bar vertical line , Vertical line i The two endpoints of are (i, ai) and (i, 0) . Find two of them , Make them x A container of shafts can hold the most water .
explain : You can't tilt the container .
class Solution {
public:
int maxArea(vector<int>& height) {
int l = 0, r = height.size() - 1;
int ans = 0;
while (l < r) {
int area = min(height[l], height[r]) * (r - l);
ans = max(ans, area);
if (height[l] <= height[r]) {
++l;
}
else {
--r;
}
}
return ans;
}
};
边栏推荐
- V-show failure
- I do live e-commerce in tiktok, UK
- Top 10 in the 5.3 billion Bi Market: fansoft, Microsoft, Yonghong, sap, Baidu, IBM, SAS, smart, salesforce, Inspur soft
- Example of MATLAB dichotomy (example of finding zero point by dichotomy)
- Sword finger offer notes: t57 - I. and two numbers of S
- STS下载教程(include官网无法下载解决方案)
- Sword finger offer note: T39. Numbers that appear more than half of the time in the array
- No matching distribution found for flask_ A solution to compat
- Write and read system temporary files: createtempfile and tempfilecontent[easy to understand]
- LNMP architecture setup (deploy discuz Forum)
猜你喜欢

EfficientNet

Chapter 13 IO flow

解决方案:idea project没有显示树状图

Wilcoxon rank sum and signed rank

上半年火灾起数下降27.7%,广东将这样提升全民消防安全素质

Solve the problem of @onetomany query falling into circular reference

Chapter 7 exception handling

SMA TE: Semi-Supervised Spatio-Temporal RepresentationLearning on Multivariate Time Series

Newton Raphson iterative method

Principle, concept and construction process of MySQL database master-slave replication cluster
随机推荐
你尚未连接代理服务器可能有问题或地址不正确(如何查看代理服务器ip)
微信小程序必用接口「建议收藏」
Sword finger offer notes: t58 - ii Rotate string left
银行人脸识别系统被攻破:一储户被偷走 43 万元
JS string method summary
Redis data type
Detailed explanation of flask framework
compute_ class_ weight() takes 1 positional argument but 3 were given
Shell脚本文本三剑客之awk
Sword finger offer notes: T53 - I. find numbers in the sorted array
关于离线缓存Application Cache /使用 manifest文件缓存
Sword finger offer notes: t57 - ii Continuous positive sequence with sum s
Regular expression of shell programming (grep of shell script text three swordsmen)
53 亿 BI 市场 TOP 10:帆软、微软、永洪、SAP、百度、IBM、SAS、思迈特、Salesforce、浪潮通软
NewTicker使用
Advance in the flutter project_ image_ Picker component usage
Chapter 8 multithreading
Top 10 in the 5.3 billion Bi Market: fansoft, Microsoft, Yonghong, sap, Baidu, IBM, SAS, smart, salesforce, Inspur soft
Solve the problem of @onetomany query falling into circular reference
JS-寄生组合式继承