当前位置:网站首页>[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)
边栏推荐
- 1035 Password
- H5 jump applet
- With an amount of $50billion, amd completed the acquisition of Xilinx
- 6. Network - Foundation
- Visual Studio导入
- [personal test] copy and paste code between VirtualBox virtual machine and local
- Fabric. JS free draw rectangle
- Alibaba: open source and self-developed liquid cooling data center technology
- RGB 无限立方体(高级版)
- kmp思想及模板代码
猜你喜欢

15 C language advanced dynamic memory management

Résumé de la collection de plug - ins couramment utilisée dans les outils de développement idea

KMP idea and template code

文件包含漏洞(二)

Huawei Hongmeng OS, is it OK?

2022-2-14 learning xiangniuke project - section 23, section 5, development login and exit functions

Gee dataset: chirps pentad high resolution global grid rainfall dataset

brew install * 失败,解决方法

Fabric. JS gradient

记录sentry的踩坑之路
随机推荐
Determine whether there is an element in the string type
Thread pool batch processing data
idea開發工具常用的插件合集匯總
Using QA band and bit mask in Google Earth engine
软件测试 - 概念篇
【LeetCode】Day92-盛最多水的容器
小程序跳装到公众号
Online music player app
Installation du tutoriel MySQL 8.0.22 par centos8
中小型项目手撸过滤器实现认证与授权
Php/js cookie sharing across domains
Matplotlib double Y axis + adjust legend position
RGB infinite cube (advanced version)
Fabric. JS round brush
指针使用详解
How to write good code - Defensive Programming Guide
"Simple" infinite magic cube
来啦~ 使用 EasyExcel 导出时进行数据转换系列新篇章!
Huawei Hongmeng OS, is it OK?
生成二维码