当前位置:网站首页>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
总结
双指针贪心去除最短板
边栏推荐
- There are several levels of personal income tax
- FBI warning: some people use AI to disguise themselves as others for remote interview
- 2022-2028 global solid phase extraction column industry research and trend analysis report
- SSH 远程执行命令简介
- Use of unsafe class
- Torch learning notes (2) -- 11 common operation modes of tensor
- [Yu Yue education] world reference materials of Microbiology in Shanghai Jiaotong University
- Gao Qing, Beijing University of Aeronautics and Astronautics: CIM is a natural quantum computing platform for graph data processing
- 统计图像中各像素值的数量
- Recent learning experience
猜你喜欢
Valentine's day, send you a little red flower~
[Godot] add menu button
Nodejs (01) - introductory tutorial
What is SQL get connection
Summary and Reflection on the third week of winter vacation
There are several levels of personal income tax
2022-2028 global lithium battery copper foil industry research and trend analysis report
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
SQL injection -day16
Unity webgl optimization
随机推荐
Prototype inheritance..
English語法_名詞 - 分類
TypeScript 官网教程
Reading a line from ifstream into a string variable
[untitled]
198. Looting - Dynamic Planning
Theoretical description of linear equations and summary of methods for solving linear equations by eigen
Unity webgl optimization
2022-2028 global aircraft head up display (HUD) industry research and trend analysis report
[combinatorics] generating function (positive integer splitting | repeated ordered splitting | non repeated ordered splitting | proof of the number of repeated ordered splitting schemes)
[combinatorics] generating function (example of generating function | calculating generating function with given general term formula | calculating general term formula with given generating function)
Torch learning notes (2) -- 11 common operation modes of tensor
[Yu Yue education] world reference materials of Microbiology in Shanghai Jiaotong University
Gao Qing, Beijing University of Aeronautics and Astronautics: CIM is a natural quantum computing platform for graph data processing
[combinatorics] generating function (commutative property | derivative property | integral property)
Okaleido, a multimedia NFT aggregation platform, is about to go online, and a new NFT era may come
Computer graduation design PHP campus address book telephone number inquiry system
Niuke monthly race 31 minus integer
Computer graduation design PHP sports goods online sales system website
Ping problem between virtual machine and development board