当前位置:网站首页>leetcode:11. 盛最多水的容器【雙指針 + 貪心 + 去除最短板】
leetcode:11. 盛最多水的容器【雙指針 + 貪心 + 去除最短板】
2022-07-03 18:39: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
總結
雙指針貪心去除最短板
边栏推荐
- Reading a line from ifstream into a string variable
- [combinatorics] exponential generating function (example of exponential generating function solving multiple set arrangement)
- 虚拟机和开发板互Ping问题
- Reappearance of ASPP (atlas spatial pyramid pooling) code
- 毕业总结
- Setinterval CPU intensive- Is setInterval CPU intensive?
- 2022-2028 global sepsis treatment drug industry research and trend analysis report
- Kratos微服务框架下实现CQRS架构模式
- How to analyze the rising and falling rules of London gold trend chart
- This diversion
猜你喜欢

Administrative division code acquisition

How to draw non overlapping bubble chart in MATLAB

Shell script return value with which output

Win 11 major updates, new features love love.

Chisel tutorial - 06 Phased summary: implement an FIR filter (chisel implements 4-bit FIR filter and parameterized FIR filter)

SQL injection -day16

2022-2028 global solid phase extraction column industry research and trend analysis report

Xception for deeplab v3+ (including super detailed code comments and original drawing of the paper)
![[Godot] add menu button](/img/44/ef1e6ac25bcbc8cc3ecc00c52f8ee2.jpg)
[Godot] add menu button

The vscode code is automatically modified to a compliance code when it is formatted and saved
随机推荐
Recent learning experience
[combinatorics] generating function (generating function application scenario | using generating function to solve recursive equation)
Common PostgreSQL commands
Mysql45 lecture learning notes (II)
Image 24 bit depth to 8 bit depth
[combinatorics] generating function (example of generating function | calculating generating function with given general term formula | calculating general term formula with given generating function)
硬盘监控和分析工具:Smartctl
Xception for deeplab v3+ (including super detailed code comments and original drawing of the paper)
[untitled]
2022-2028 global plasmid DNA cdmo industry research and trend analysis report
Why can deeplab v3+ be a God? (the explanation of the paper includes super detailed notes + Chinese English comparison + pictures)
Computer graduation design PHP campus address book telephone number inquiry system
Computer graduation design PHP makeup sales Beauty shopping mall
There are several levels of personal income tax
FBI 警告:有人利用 AI 换脸冒充他人身份进行远程面试
041. (2.10) talk about manpower outsourcing
Reappearance of ASPP (atlas spatial pyramid pooling) code
English grammar_ Adjective / adverb Level 3 - multiple expression
Raft 日志复制
English语法_形容词/副词3级 - 倍数表达