当前位置:网站首页>【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)
边栏推荐
- 文件包含漏洞(二)
- 1037 Magic Coupon
- Gee: remote sensing image composite and mosaic
- ERP management system development and design existing source code
- 【pyinstaller】_ get_ sysconfigdata_ name() missing 1 required positional argument: ‘check_ exists‘
- Gee: create a new feature and set corresponding attributes
- Yyds dry inventory what is test driven development
- 7.TCP的十一种状态集
- Pytorch Basics
- 在线音乐播放器app
猜你喜欢
![[golang syntax] be careful with the copy of slices](/img/5e/1c82c58940939b94d03377ebdc03e3.jpg)
[golang syntax] be careful with the copy of slices

Fabric. JS iText set italics manually

【pyinstaller】_ get_ sysconfigdata_ name() missing 1 required positional argument: ‘check_ exists‘

Storage of data

centos8安装mysql8.0.22教程

Gee series: Unit 1 Introduction to Google Earth engine

Basic use of form

记录sentry的踩坑之路

JVM class loading mechanism

Ls1046nfs mount file system
随机推荐
2022-2-14 learning xiangniuke project - section 23, section 5, development login and exit functions
Online music player app
Gee: use of common mask functions in remote sensing image processing [updatemask]
数据库批量插入数据
Common protocols and download paths of NR
centos8安装mysql8.0.22教程
idea开发工具常用的插件合集汇总
Win10 copy files, save files... All need administrator permission, solution
7.TCP的十一种状态集
Ubuntu 20.04 installing mysql8
Installation du tutoriel MySQL 8.0.22 par centos8
Zzuli:1061 sequential output of digits
Gee series: unit 10 creating a graphical user interface using Google Earth engine [GUI development]
Minimum value ruler method for the length of continuous subsequences whose sum is not less than s
Huawei Hongmeng OS, is it OK?
Balsamiq wireframes free installation
Fabric. JS basic brush
1036 Boys vs Girls
Zzuli:1067 faulty odometer
Fabric. JS iText superscript and subscript