当前位置:网站首页>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
边栏推荐
- Coordinate layer conversion tool (video)
- Bidding procurement scheme management of Oracle project management system
- [combinatorics] generating function (use generating function to solve the combination number of multiple sets R)
- [enumeration] annoying frogs always step on my rice fields: (who is the most hateful? (POJ hundred practice 2812)
- Day-27 database
- The vscode code is automatically modified to a compliance code when it is formatted and saved
- Recent learning experience
- Unity2018 to wechat games without pictures
- Ping problem between virtual machine and development board
- my. INI file not found
猜你喜欢

How do microservices aggregate API documents? This wave of operation is too good

Gao Qing, Beijing University of Aeronautics and Astronautics: CIM is a natural quantum computing platform for graph data processing

Administrative division code acquisition

Theoretical description of linear equations and summary of methods for solving linear equations by eigen

MySQL duplicate check

Naoqi robot summary 27

平淡的生活里除了有扎破皮肤的刺,还有那些原本让你魂牵梦绕的诗与远方

Summary and Reflection on the third week of winter vacation

What problems can cross-border e-commerce sellers solve with multi platform ERP management system

2022-2028 global sepsis treatment drug industry research and trend analysis report
随机推荐
[combinatorics] generating function (positive integer splitting | unordered non repeated splitting example)
Sensor 调试流程
Ping problem between virtual machine and development board
[combinatorics] generating function (example of using generating function to solve the number of solutions of indefinite equation)
How to draw non overlapping bubble chart in MATLAB
The number of incremental paths in the grid graph [dfs reverse path + memory dfs]
Web3 credential network project galaxy is better than nym?
Software development freelancer's Road
Image 24 bits de profondeur à 8 bits de profondeur
Mysql45 lecture learning notes (II)
Closure and closure function
English grammar_ Adjective / adverb Level 3 - multiple expression
How about the Moco model?
Getting started with JDBC
[combinatorics] generating function (use generating function to solve the number of solutions of indefinite equation example 2 | extended to integer solution)
php-fpm的max_chindren的一些误区
English語法_名詞 - 分類
Shell script return value with which output
How does GCN use large convolution instead of small convolution? (the explanation of the paper includes super detailed notes + Chinese English comparison + pictures)
Niuke monthly race 31 minus integer