当前位置:网站首页>[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)
边栏推荐
猜你喜欢
Detailed explanation of Pointer use
"Simple" infinite magic cube
VSCode paste image插件保存图片路径设置
Lingyunguang rushes to the scientific innovation board: the annual accounts receivable reaches 800million. Dachen and Xiaomi are shareholders
Fabric. JS activation input box
all3dp.com网站中全部Arduino项目(2022.7.1)
Installation du tutoriel MySQL 8.0.22 par centos8
ThreadLocal memory leak
Go language web development is very simple: use templates to separate views from logic
A collection of commonly used plug-ins for idea development tools
随机推荐
[Chongqing Guangdong education] selected reading reference materials of British and American literature of Nanyang Normal University
Zzuli:1061 sequential output of digits
Zzuli:1068 binary number
3D printer G code command: complete list and tutorial
RGB infinite cube (advanced version)
Reflection of the soul of the frame (important knowledge)
Basic use of form
Principle and implementation of parallax effect
Installation du tutoriel MySQL 8.0.22 par centos8
Gee series: Unit 5 remote sensing image preprocessing [GEE grid preprocessing]
Fabric. JS round brush
With an amount of $50billion, amd completed the acquisition of Xilinx
Applet jumps to official account
Technologists talk about open source: This is not just using love to generate electricity
Using QA band and bit mask in Google Earth engine
Go language web development is very simple: use templates to separate views from logic
Software testing learning - day 4
3D 打印机 G 代码命令:完整列表和教程
Disable access to external entities in XML parsing
Gee: analyze the change of spatial centroid of remote sensing image [centroid acquisition analysis]