当前位置:网站首页>【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)
边栏推荐
- 3D printer G code command: complete list and tutorial
- Storage of data
- Fabric. JS basic brush
- 7. Eleven state sets of TCP
- ERP management system development and design existing source code
- Gee: explore the characteristics of precipitation change in the Yellow River Basin in the past 10 years [pixel by pixel analysis]
- Go language web development is very simple: use templates to separate views from logic
- Gee series: unit 6 building various remote sensing indexes in Google Earth engine
- Zzuli:1069 learn from classmate Z
- Ls1046nfs mount file system
猜你喜欢

Detailed explanation of Pointer use

Using QA band and bit mask in Google Earth engine

数据的储存

5g market trend in 2020

Gee series: Unit 3 raster remote sensing image band characteristics and rendering visualization

死磕大屏UI,FineReport开发日记

软件测试基础篇

Storage of data

Balsamiq wireframes free installation

Fabric. JS compact JSON
随机推荐
Gee dataset: chirps pentad high resolution global grid rainfall dataset
“簡單”的無限魔方
Database batch insert data
Zzuli:1069 learn from classmate Z
Importation de studio visuel
Thunder on the ground! Another domestic 5g chip comes out: surpass Huawei and lead the world in performance?
Nodejs (02) - built in module
Small and medium-sized projects to achieve certification and authorization of hand filter
Uva548 tree
7.TCP的十一种状态集
Mysql基础---查询(1天学会mysql基础)
Gee series: Unit 1 Introduction to Google Earth engine
软件测试答疑篇
Cube magique infini "simple"
Pytorch Basics
6.网络-基础
Opencv LBP features
Ls1046nfs mount file system
Fabric. JS activation input box
7. Eleven state sets of TCP