当前位置:网站首页>[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)
边栏推荐
- Zzuli:1067 faulty odometer
- Usage record of vector
- Fabric. JS iText set italics manually
- Fabric. JS basic brush
- Zzuli:1064 encrypted characters
- Sliding window on the learning road
- 线程池概述
- 【pyinstaller】_ get_ sysconfigdata_ name() missing 1 required positional argument: ‘check_ exists‘
- 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
- all3dp.com网站中全部Arduino项目(2022.7.1)
猜你喜欢

Alibaba: open source and self-developed liquid cooling data center technology

Gee: remote sensing image composite and mosaic

Thunder on the ground! Another domestic 5g chip comes out: surpass Huawei and lead the world in performance?

Gee series: Unit 1 Introduction to Google Earth engine

JVM class loading mechanism
![[personal test] copy and paste code between VirtualBox virtual machine and local](/img/ce/eaf0bd9eff6551d450964da72e0b63.jpg)
[personal test] copy and paste code between VirtualBox virtual machine and local

Pytorch Basics

2022-2-14 learning xiangniuke project - Section 7 account setting

记录sentry的踩坑之路

Appnuim environment configuration and basic knowledge
随机推荐
Installation du tutoriel MySQL 8.0.22 par centos8
Zzuli:1062 greatest common divisor
线程池概述
Taskbar explicit / implicit toggle function
Detailed explanation of Pointer use
Determine whether there is an element in the string type
Database batch insert data
idea開發工具常用的插件合集匯總
Thread pool overview
3D 打印机 G 代码命令:完整列表和教程
软件测试基础篇
来啦~ 使用 EasyExcel 导出时进行数据转换系列新篇章!
“簡單”的無限魔方
all3dp.com网站中全部Arduino项目(2022.7.1)
h5跳小程序
Centos8 installation mysql8.0.22 tutorial
15 C language advanced dynamic memory management
ERP management system development and design existing source code
Php/js cookie sharing across domains
Cambrian was reduced by Paleozoic venture capital and Zhike shengxun: a total of more than 700million cash