当前位置:网站首页>[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)
边栏推荐
- RNN recurrent neural network
- centos8安装mysql8.0.22教程
- 文件包含漏洞(二)
- 在线音乐播放器app
- Cube magique infini "simple"
- 15 C language advanced dynamic memory management
- Record sentry's path of stepping on the pit
- Fabric. JS background is not affected by viewport transformation
- Common protocols and download paths of NR
- Gee: use of common mask functions in remote sensing image processing [updatemask]
猜你喜欢
3D printer G code command: complete list and tutorial
Appnuim environment configuration and basic knowledge
“簡單”的無限魔方
Basic use of form
Lingyunguang rushes to the scientific innovation board: the annual accounts receivable reaches 800million. Dachen and Xiaomi are shareholders
Fabric. JS right click menu
Gee: remote sensing image composite and mosaic
Huawei Hongmeng OS, is it OK?
Go language web development is very simple: use templates to separate views from logic
“简单”的无限魔方
随机推荐
Online music player app
Thunder on the ground! Another domestic 5g chip comes out: surpass Huawei and lead the world in performance?
GRBL 软件:简单解释的基础知识
Importation de studio visuel
brew install * 失败,解决方法
中小型项目手撸过滤器实现认证与授权
Record sentry's path of stepping on the pit
软件测试基础篇
Gee series: unit 10 creating a graphical user interface using Google Earth engine [GUI development]
Reflection of the soul of the frame (important knowledge)
How matlab marks' a 'in the figure and how matlab marks points and solid points in the figure
"Original, excellent and vulgar" in operation and maintenance work
Fabric. JS three methods of changing pictures (including changing pictures in the group and caching)
How to change the IP address of computer mobile phone simulator
Win10 copy files, save files... All need administrator permission, solution
Fabric. JS iText sets the color and background color of the specified text
JVM class loading mechanism
1037 Magic Coupon
Huawei Hongmeng OS, is it OK?
XSS basic content learning (continuous update)