当前位置:网站首页>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
总结
双指针贪心去除最短板
边栏推荐
- 2022-2028 global copper foil (thickness 12 μ M) 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)
- 平淡的生活里除了有扎破皮肤的刺,还有那些原本让你魂牵梦绕的诗与远方
- 圖像24比特深度轉8比特深度
- Opencv learning notes (continuously updated)
- 4. Load balancing and dynamic static separation
- Sepconv (separable revolution) code recurrence
- 042. (2.11) do it when it's time to do it
- Kratos微服务框架下实现CQRS架构模式
- Count the number of pixel values in the image
猜你喜欢

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

G1 garbage collector of garbage collector

Computer graduation design PHP campus address book telephone number inquiry system

Implementation of cqrs architecture mode under Kratos microservice framework

Read the paper glodyne global topology preserving dynamic network embedding

FBI warning: some people use AI to disguise themselves as others for remote interview

Class exercises

English语法_名词 - 分类

Su embedded training - Day10

How does GCN use large convolution instead of small convolution? (the explanation of the paper includes super detailed notes + Chinese English comparison + pictures)
随机推荐
Typescript configuration
[combinatorics] generating function (commutative property | derivative property | integral property)
What London Silver Trading software supports multiple languages
Raft 日志复制
How to expand the capacity of golang slice slice
Computer graduation design PHP makeup sales Beauty shopping mall
Recent learning experience
Database creation, addition, deletion, modification and query
FBI warning: some people use AI to disguise themselves as others for remote interview
[untitled]
198. Looting - Dynamic Planning
[combinatorics] generating function (positive integer splitting | repeated ordered splitting | non repeated ordered splitting | proof of the number of repeated ordered splitting schemes)
Okaleido, a multimedia NFT aggregation platform, is about to go online, and a new NFT era may come
[combinatorics] exponential generating function (properties of exponential generating function | exponential generating function solving multiple set arrangement)
Count the number of pixel values in the image
[combinatorics] exponential generating function (concept of exponential generating function | permutation number exponential generating function = combinatorial number ordinary generating function | e
Real time split network (continuous update)
简述服务量化分析体系
毕业总结
Boost. Asio Library