当前位置:网站首页>【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)
边栏推荐
猜你喜欢
[golang syntax] be careful with the copy of slices
2022-2-15 learning xiangniuke project - Section 8 check login status
Software testing learning - day 4
Gee series: Unit 3 raster remote sensing image band characteristics and rendering visualization
"Original, excellent and vulgar" in operation and maintenance work
Technologists talk about open source: This is not just using love to generate electricity
idea開發工具常用的插件合集匯總
Opencv LBP features
Principle and implementation of parallax effect
Fabric. JS right click menu
随机推荐
Fabric. JS upload local image to canvas background
6.网络-基础
Online English teaching app open source platform (customized)
《CGNF: CONDITIONAL GRAPH NEURAL FIELDS》阅读笔记
软件测试基础篇
Gee: explore the change of water area in the North Canal basin over the past 30 years [year by year]
测试 - 用例篇
6. Network - Foundation
Typora installation (no need to enter serial number)
Visual Studio导入
Online music player app
Fabric. JS background is not affected by viewport transformation
【论文翻译】GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond
Innovation never stops -- the innovation process of nvisual network visualization platform for Excel import
Zzuli:1069 learn from classmate Z
Fabric. JS round brush
Gee series: Unit 1 Introduction to Google Earth engine
延时队列两种实现方式
centos8安裝mysql8.0.22教程
Ls1046nfs mount file system