当前位置:网站首页>Leetcode: 11. Récipient contenant le plus d'eau [double pointeur + cupidité + enlèvement de la plaque la plus courte]
Leetcode: 11. Récipient contenant le plus d'eau [double pointeur + cupidité + enlèvement de la plaque la plus courte]
2022-07-03 18:39:00 【Rétrospective du roi dragon blanc】
Analyse
Au début, les deux pointeurs pointent vers une extrémité
Et regarde ce petit,Déplacez - le au milieu(Le but est d'enlever la plaque la plus courte,Il est possible de devenir plus grand)
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))
# Avidité:Retirer la plaque la plus courte
if height[l] < height[r]:
l += 1
else:
r -= 1
return ans
Résumé
Double pointeur avide enlever la plaque la plus courte
边栏推荐
- Should I be laid off at the age of 40? IBM is suspected of age discrimination, calling its old employees "dinosaurs" and planning to dismiss, but the employees can't refute it
- NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
- Redis cache avalanche, penetration, breakdown
- 198. Looting - Dynamic Planning
- 企业级自定义表单引擎解决方案(十二)--表单规则引擎2
- How do microservices aggregate API documents? This wave of operation is too good
- Read the paper glodyne global topology preserving dynamic network embedding
- FBI 警告:有人利用 AI 换脸冒充他人身份进行远程面试
- How to read the source code [debug and observe the source code]
- 042. (2.11) do it when it's time to do it
猜你喜欢
Data analysis is popular on the Internet, and the full version of "Introduction to data science" is free to download
[combinatorics] dislocation problem (recursive formula | general term formula | derivation process)*
Valentine's day, send you a little red flower~
How to expand the capacity of golang slice slice
2022-2028 global aircraft head up display (HUD) industry research and trend analysis report
An academic paper sharing and approval system based on PHP for computer graduation design
2022-2028 global plasmid DNA cdmo industry research and trend analysis report
Torch learning notes (7) -- take lenet as an example for dataload operation (detailed explanation + reserve knowledge supplement)
Win 11 major updates, new features love love.
Sensor debugging process
随机推荐
2022-2028 global petroleum pipe joint industry research and trend analysis report
How to analyze the rising and falling rules of London gold trend chart
企业级自定义表单引擎解决方案(十二)--表单规则引擎2
This diversion
12、 Service management
Recommend a simple browser tab
[Godot] add menu button
编程中常见的 Foo 是什么意思?
2022-2028 global sepsis treatment drug industry research and trend analysis report
Gao Qing, Beijing University of Aeronautics and Astronautics: CIM is a natural quantum computing platform for graph data processing
G1 garbage collector of garbage collector
硬盘监控和分析工具:Smartctl
[combinatorics] exponential generating function (example 2 of solving multiple set permutation with exponential generating function)
SSH 远程执行命令简介
Read the paper glodyne global topology preserving dynamic network embedding
Administrative division code acquisition
[combinatorics] generating function (example of generating function | calculating generating function with given general term formula | calculating general term formula with given generating function)
Analysis of the reasons why enterprises build their own software development teams to use software manpower outsourcing services at the same time
4. Load balancing and dynamic static separation
How about the Moco model?