当前位置:网站首页>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
边栏推荐
- After nohup NPM start &, close the shell window directly, and the process closes accordingly
- Prototype inheritance..
- Xception for deeplab v3+ (including super detailed code comments and original drawing of the paper)
- 2022-2028 global copper foil (thickness 12 μ M) industry research and trend analysis report
- SQL: special update operation
- webcodecs
- php-fpm的max_chindren的一些误区
- Read the paper glodyne global topology preserving dynamic network embedding
- [combinatorics] generating function (example of generating function | calculating generating function with given general term formula | calculating general term formula with given generating function)
- Software development freelancer's Road
猜你喜欢

Computer graduation design PHP makeup sales Beauty shopping mall

CV in transformer learning notes (continuously updated)

12、 Service management

Real time split network (continuous update)

What kind of experience is it when the Institute earns 20000 yuan a month?

多媒体NFT聚合平台OKALEIDO即将上线,全新的NFT时代或将来临

Opencv learning notes (continuously updated)

How to expand the capacity of golang slice slice

Valentine's day, send you a little red flower~

Torch learning notes (7) -- take lenet as an example for dataload operation (detailed explanation + reserve knowledge supplement)
随机推荐
2022-2028 global marking ink industry research and trend analysis report
2022.02.11
Torch learning notes (5) -- autograd
Torch learning notes (2) -- 11 common operation modes of tensor
Niuke monthly race 31 minus integer
English grammar_ Adjective / adverb Level 3 - multiple expression
论文阅读 GloDyNE Global Topology Preserving Dynamic Network Embedding
Torch learning notes (3) -- univariate linear regression model (self training)
Bloom filter [proposed by bloom in 1970; redis cache penetration solution]
Raft 日志复制
TypeScript 官网教程
There are several levels of personal income tax
Have you learned the correct expression posture of programmers on Valentine's day?
Change the single node of Postgres database into master-slave
Torch learning notes (4) -- torch's dynamic calculation diagram
[combinatorics] generating function (use generating function to solve the combination number of multiple sets R)
Unity2018 to wechat games without pictures
How to analyze the rising and falling rules of London gold trend chart
042. (2.11) do it when it's time to do it
2022-2028 global petroleum pipe joint industry research and trend analysis report