当前位置:网站首页>【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)
边栏推荐
- ThreadLocal memory leak
- Gee: create a new feature and set corresponding attributes
- 生成二维码
- Balsamiq wireframes free installation
- How to write good code - Defensive Programming Guide
- Gee: analyze the change of spatial centroid of remote sensing image [centroid acquisition analysis]
- GRBL 软件:简单解释的基础知识
- Matplotlib double Y axis + adjust legend position
- Gee series: unit 9 generate sampling data in GEE [random sampling]
- Gee series: Unit 3 raster remote sensing image band characteristics and rendering visualization
猜你喜欢

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

3D 打印机 G 代码命令:完整列表和教程

"Original, excellent and vulgar" in operation and maintenance work

With an amount of $50billion, amd completed the acquisition of Xilinx

Pytorch Basics
![Gee series: Unit 5 remote sensing image preprocessing [GEE grid preprocessing]](/img/1e/cf0aa09c2fce2278386f12eae4a6cd.jpg)
Gee series: Unit 5 remote sensing image preprocessing [GEE grid preprocessing]

brew install * 失败,解决方法

Thunder on the ground! Another domestic 5g chip comes out: surpass Huawei and lead the world in performance?

Huawei Hongmeng OS, is it OK?

Technologists talk about open source: This is not just using love to generate electricity
随机推荐
Fabric. JS round brush
Huawei Hongmeng OS, is it OK?
Go language web development is very simple: use templates to separate views from logic
延时队列两种实现方式
Gee series: unit 9 generate sampling data in GEE [random sampling]
php/js cookie共享跨域的问题
1035 Password
Gee series: Unit 5 remote sensing image preprocessing [GEE grid preprocessing]
Thread pool overview
Get the details of the next largest number
6.网络-基础
"Original, excellent and vulgar" in operation and maintenance work
小程序跳装到公众号
软件测试基础篇
Determine whether there is an element in the string type
Brew install * failed, solution
7. Eleven state sets of TCP
Grbl software: basic knowledge of simple explanation
Thread pool batch processing data
Zzuli:1065 count the number of numeric characters