当前位置:网站首页>[leetcode] day92 container with the most water
[leetcode] day92 container with the most water
2022-07-02 05:44:00 【Upside down, it's a circle】
subject
11. Container for the most water 【 secondary 】
Answer key
Double pointer practice : The double pointer starts on both sides , Calculate the water volume of the container at this time , If it is greater than max, Update max; Which side moves low after that , Move in the middle , Repeat the above steps to update max, Until all vertical lines are traversed
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;
}
}
Time complexity : O ( n ) O(n) O(n)
Spatial complexity : O ( 1 ) O(1) O(1)
边栏推荐
- Pytorch Basics
- 1035 Password
- 操作符详解
- Gee: create a new feature and set corresponding attributes
- Fabric. JS iText set italics manually
- 2022-2-14 learning xiangniuke project - Section 7 account setting
- Installation du tutoriel MySQL 8.0.22 par centos8
- Fabric. JS gradient
- Zzuli:1065 count the number of numeric characters
- Record sentry's path of stepping on the pit
猜你喜欢

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

RGB 无限立方体(高级版)

Software testing learning - day 4

The Hong Kong Stock Exchange learned from US stocks and pushed spac: the follow-up of many PE companies could not hide the embarrassment of the world's worst stock market
![[technical notes-08]](/img/52/0aff21b01ba7adbfcdb597d1aa85f9.png)
[technical notes-08]

Gee: create a new feature and set corresponding attributes

all3dp.com网站中全部Arduino项目(2022.7.1)

Gee series: unit 6 building various remote sensing indexes in Google Earth engine

Matplotlib double Y axis + adjust legend position

centos8安装mysql8.0.22教程
随机推荐
I want to understand the swift code before I learn it. I understand it
460. LFU cache bidirectional linked list
记录sentry的踩坑之路
Common protocols and download paths of NR
Gee series: unit 6 building various remote sensing indexes in Google Earth engine
brew install * 失败,解决方法
Zzuli:1061 sequential output of digits
Minimum value ruler method for the length of continuous subsequences whose sum is not less than s
1036 Boys vs Girls
[Chongqing Guangdong education] selected reading reference materials of British and American literature of Nanyang Normal University
“简单”的无限魔方
Record sentry's path of stepping on the pit
OLED12864 液晶屏
软件测试基础篇
Fabric. JS three methods of changing pictures (including changing pictures in the group and caching)
Php/js cookie sharing across domains
ThreadLocal memory leak
Pytorch Basics
Small and medium-sized projects to achieve certification and authorization of hand filter
1035 Password