当前位置:网站首页>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
边栏推荐
- Computer graduation design PHP makeup sales Beauty shopping mall
- Gao Qing, Beijing University of Aeronautics and Astronautics: CIM is a natural quantum computing platform for graph data processing
- Pan for in-depth understanding of the attention mechanism in CV
- Class exercises
- Coordinate layer conversion tool (video)
- 22.2.14 -- station B login with code -for circular list form - 'no attribute' - 'needs to be in path selenium screenshot deviation -crop clipping error -bytesio(), etc
- Torch learning notes (2) -- 11 common operation modes of tensor
- How does GCN use large convolution instead of small convolution? (the explanation of the paper includes super detailed notes + Chinese English comparison + pictures)
- Database creation, addition, deletion, modification and query
- [combinatorics] generating function (positive integer splitting | unordered | ordered | allowed repetition | not allowed repetition | unordered not repeated splitting | unordered repeated splitting)
猜你喜欢
Getting started with JDBC
Mysql45 lecture learning notes (II)
Computer graduation design PHP sports goods online sales system website
CTO and programmer were both sentenced for losing control of the crawler
Bloom filter [proposed by bloom in 1970; redis cache penetration solution]
VLAN experiment
Install apache+php+mysql+phpmyadmin xampp and its error resolution
Sensor debugging process
Computer graduation design PHP makeup sales Beauty shopping mall
Why can deeplab v3+ be a God? (the explanation of the paper includes super detailed notes + Chinese English comparison + pictures)
随机推荐
Multifunctional web file manager filestash
PHP determines which constellation it belongs to today
Sensor debugging process
Transformer T5 model read slowly
Usage of laravel conditional array in
2022-2028 global plasmid DNA cdmo industry research and trend analysis report
How to quickly view the inheritance methods of existing models in torchvision?
Suffix derivation based on query object fields
2022-2028 global physiotherapy clinic industry research and trend analysis report
Graduation summary
2022-2028 global marking ink industry research and trend analysis report
How do microservices aggregate API documents? This wave of operation is too good
[combinatorics] dislocation problem (recursive formula | general term formula | derivation process)*
Raft log replication
G1 garbage collector of garbage collector
Torch learning notes (3) -- univariate linear regression model (self training)
Kratos微服务框架下实现CQRS架构模式
How to analyze the rising and falling rules of London gold trend chart
How about the Moco model?
[combinatorics] generating function (use generating function to solve the number of solutions of indefinite equation)