当前位置:网站首页>【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)
边栏推荐
- Online music player app
- 延时队列两种实现方式
- 软件测试 - 概念篇
- RGB 无限立方体(高级版)
- [golang syntax] be careful with the copy of slices
- Fabric. JS iText superscript and subscript
- Generate QR code
- 2022-2-14 learning xiangniuke project - section 23, section 5, development login and exit functions
- Php/js cookie sharing across domains
- [personal test] copy and paste code between VirtualBox virtual machine and local
猜你喜欢
6. Network - Foundation
Detailed explanation of Pointer use
6.网络-基础
"Simple" infinite magic cube
Résumé de la collection de plug - ins couramment utilisée dans les outils de développement idea
2022-2-14 learning xiangniuke project - Section 6 displays login information
Gee series: Unit 4 data import and export in Google Earth engine
Straighten elements (with transition animation)
记录sentry的踩坑之路
idea开发工具常用的插件合集汇总
随机推荐
Disable access to external entities in XML parsing
Detailed explanation of Pointer use
Gee series: unit 7 remote sensing image classification using GEE [random forest classification]
Gee series: Unit 3 raster remote sensing image band characteristics and rendering visualization
RGB infinite cube (advanced version)
Gee series: unit 8 time series analysis in Google Earth engine [time series]
H5 jump applet
1036 Boys vs Girls
Gee series: Unit 1 Introduction to Google Earth engine
2022-2-14 learning xiangniuke project - section 23, section 5, development login and exit functions
Gee: use of common mask functions in remote sensing image processing [updatemask]
【技术随记-08】
Thunder on the ground! Another domestic 5g chip comes out: surpass Huawei and lead the world in performance?
中小型项目手撸过滤器实现认证与授权
如何写出好代码 — 防御式编程指南
Software testing learning - day 4
3D 打印机 G 代码命令:完整列表和教程
Opencv LBP features
Php/js cookie sharing across domains
线程池批量处理数据