当前位置:网站首页>【LeetCode】Day92-盛最多水的容器
【LeetCode】Day92-盛最多水的容器
2022-07-02 05:40:00 【倒过来是圈圈】
题目
题解
双指针做法:双指针最开始在两边,计算此时容器水量,如果大于max,则更新max;之后哪边矮动哪边,往中间移动,重复上述步骤更新max,直到遍历完所有垂线
class Solution {
public int maxArea(int[] height) {
int l=0,r=height.length-1,max=0;
while(l<r){
int area=Math.min(height[l],height[r])*(r-l);
max=Math.max(area,max);
if(height[l]<height[r])
l++;
else
r--;
}
return max;
}
}
时间复杂度: O ( n ) O(n) O(n)
空间复杂度: O ( 1 ) O(1) O(1)
边栏推荐
- 简单封装 js并应用
- Nodejs (02) - built in module
- 指针使用详解
- all3dp.com网站中全部Arduino项目(2022.7.1)
- Zzuli:1061 sequential output of digits
- H5 jump applet
- 操作符详解
- Fabric. JS right click menu
- Detailed explanation of Pointer use
- [Chongqing Guangdong education] selected reading reference materials of British and American literature of Nanyang Normal University
猜你喜欢

Storage of data

Straighten elements (with transition animation)

操作符详解
![Gee: explore the change of water area in the North Canal basin over the past 30 years [year by year]](/img/7b/b9ef76cee8b32204331a9c3c21b5c2.jpg)
Gee: explore the change of water area in the North Canal basin over the past 30 years [year by year]

“簡單”的無限魔方

OLED12864 液晶屏

Gee data set: export the distribution and installed capacity of hydropower stations in the country to CSV table
![[technical notes-08]](/img/52/0aff21b01ba7adbfcdb597d1aa85f9.png)
[technical notes-08]

Minimum value ruler method for the length of continuous subsequences whose sum is not less than s

3D printer G code command: complete list and tutorial
随机推荐
Fabric. JS upload local image to canvas background
Gee series: unit 9 generate sampling data in GEE [random sampling]
Zzuli:1066 character classification statistics
Zzuli:1062 greatest common divisor
Gee series: Unit 2 explore datasets
Gee series: unit 7 remote sensing image classification using GEE [random forest classification]
Uva548 tree
php/js cookie共享跨域的问题
Nodejs (02) - built in module
5g market trend in 2020
Installation du tutoriel MySQL 8.0.22 par centos8
Record sentry's path of stepping on the pit
XSS basic content learning (continuous update)
1037 Magic Coupon
Nodejs (03) -- custom module
Zzuli:1067 faulty odometer
Win10 copy files, save files... All need administrator permission, solution
Importation de studio visuel
I want to understand the swift code before I learn it. I understand it
如何写出好代码 — 防御式编程指南