当前位置:网站首页>leetcode:11. Container with the most water [double pointer + greed + remove the shortest board]
leetcode:11. Container with the most water [double pointer + greed + remove the shortest board]
2022-07-03 18:39:00 【White speed Dragon King's review】
analysis
At first, the double pointer points to one end
Then see which one is smaller , Just move it to the middle ( The purpose of this is to remove the shortest board , It is possible to get bigger )
ac code
class Solution:
def maxArea(self, height: List[int]) -> int:
# double pointers
n = len(height)
l, r = 0, n - 1
ans = 0
while l < r:
ans = max(ans, min(height[l], height[r]) * (r - l))
# greedy : Remove the shortest board
if height[l] < height[r]:
l += 1
else:
r -= 1
return ans
summary
Double pointer greedy to remove the shortest board
边栏推荐
- Database creation, addition, deletion, modification and query
- [combinatorics] generating function (use generating function to solve the combination number of multiple sets R)
- Torch learning notes (7) -- take lenet as an example for dataload operation (detailed explanation + reserve knowledge supplement)
- 2022-2028 global sepsis treatment drug industry research and trend analysis report
- 2022-2028 global copper foil (thickness 12 μ M) industry research and trend analysis report
- Win 11 major updates, new features love love.
- SQL: special update operation
- php-fpm的max_chindren的一些误区
- Typescript official website tutorial
- Zero length array
猜你喜欢
VLAN experiment
SQL custom collation
Prototype inheritance..
The number of incremental paths in the grid graph [dfs reverse path + memory dfs]
Theoretical description of linear equations and summary of methods for solving linear equations by eigen
How to expand the capacity of golang slice slice
Getting started with JDBC
[Godot] add menu button
[Yu Yue education] theoretical mechanics reference materials of Shanghai Jiaotong University
CV in transformer learning notes (continuously updated)
随机推荐
SQL: special update operation
Mysql45 lecture learning notes (II)
Summary and Reflection on the third week of winter vacation
[combinatorics] generating function (use generating function to solve the number of solutions of indefinite equation example 2 | extended to integer solution)
Xception for deeplab v3+ (including super detailed code comments and original drawing of the paper)
Torch learning notes (3) -- univariate linear regression model (self training)
Niuke monthly race 31 minus integer
Boost. Asio Library
Why can deeplab v3+ be a God? (the explanation of the paper includes super detailed notes + Chinese English comparison + pictures)
Raft log replication
Naoqi robot summary 27
[combinatorics] exponential generating function (example 2 of solving multiple set permutation with exponential generating function)
Bloom filter [proposed by bloom in 1970; redis cache penetration solution]
Torch learning notes (7) -- take lenet as an example for dataload operation (detailed explanation + reserve knowledge supplement)
What problems can cross-border e-commerce sellers solve with multi platform ERP management system
FBI 警告:有人利用 AI 换脸冒充他人身份进行远程面试
Database creation, addition, deletion, modification and query
shell 脚本中关于用户输入参数的处理
Sensor 调试流程
[combinatorics] exponential generating function (example of exponential generating function solving multiple set arrangement)