当前位置:网站首页>leetcode:11. 盛最多水的容器【双指针 + 贪心 + 去除最短板】
leetcode:11. 盛最多水的容器【双指针 + 贪心 + 去除最短板】
2022-07-03 18:38:00 【白速龙王的回眸】

分析
一开始双指针指着一头一尾
然后看看哪个小,就把它往中间移动(这样做的目的是去除最短板,才有可能变大)
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))
# 贪心:去除最短板
if height[l] < height[r]:
l += 1
else:
r -= 1
return ans
总结
双指针贪心去除最短板
边栏推荐
- Common PostgreSQL commands
- Why can deeplab v3+ be a God? (the explanation of the paper includes super detailed notes + Chinese English comparison + pictures)
- After nohup NPM start &, close the shell window directly, and the process closes accordingly
- VLAN experiment
- What is SQL get connection
- Prototype inheritance..
- [combinatorics] generating function (positive integer splitting | unordered non repeated splitting example)
- MySQL duplicate check
- 2022-2028 global plasmid DNA cdmo industry research and trend analysis report
- 041. (2.10) talk about manpower outsourcing
猜你喜欢

NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon

Su embedded training - Day10

How to draw non overlapping bubble chart in MATLAB

Computer graduation design PHP campus address book telephone number inquiry system
![[leetcode周赛]第300场——6110. 网格图中递增路径的数目-较难](/img/8d/0e515af6c17971ddf461e3f3b87c30.png)
[leetcode周赛]第300场——6110. 网格图中递增路径的数目-较难

How to analyze the rising and falling rules of London gold trend chart

How many convolution methods does deep learning have? (including drawings)

Opencv learning notes (continuously updated)

Multifunctional web file manager filestash

2022-2028 global plasmid DNA cdmo industry research and trend analysis report
随机推荐
Torch learning notes (3) -- univariate linear regression model (self training)
Usage of laravel conditional array in
Coordinate layer conversion tool (video)
This diversion
Torch learning notes (5) -- autograd
[leetcode周赛]第300场——6110. 网格图中递增路径的数目-较难
VLAN experiment
Grammaire anglaise Nom - Classification
Read the paper glodyne global topology preserving dynamic network embedding
[combinatorics] generating function (use generating function to solve the number of solutions of indefinite equation example 2 | extended to integer solution)
Sensor 调试流程
How does GCN use large convolution instead of small convolution? (the explanation of the paper includes super detailed notes + Chinese English comparison + pictures)
平淡的生活里除了有扎破皮肤的刺,还有那些原本让你魂牵梦绕的诗与远方
Graduation summary
2022-2028 global physiotherapy clinic industry research and trend analysis report
Niuke monthly race 31 minus integer
[combinatorics] generating function (positive integer splitting | repeated ordered splitting | non repeated ordered splitting | proof of the number of repeated ordered splitting schemes)
Recommend a simple browser tab
Golang string (string) and byte array ([]byte) are converted to each other
How to analyze the rising and falling rules of London gold trend chart