当前位置:网站首页>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
边栏推荐
- 编程中常见的 Foo 是什么意思?
- Xception for deeplab v3+ (including super detailed code comments and original drawing of the paper)
- Administrative division code acquisition
- Web3 credential network project galaxy is better than nym?
- Recent learning experience
- Transformer T5 model read slowly
- [untitled]
- [combinatorics] generating function (example of using generating function to solve the number of solutions of indefinite equation)
- Day-27 database
- [combinatorics] exponential generating function (concept of exponential generating function | permutation number exponential generating function = combinatorial number ordinary generating function | e
猜你喜欢
Analysis of the reasons why enterprises build their own software development teams to use software manpower outsourcing services at the same time
Transformer T5 model read slowly
Read the paper glodyne global topology preserving dynamic network embedding
How to track the real-time trend of Bank of London
Mature port AI ceaspectus leads the world in the application of AI in terminals, CIMC Feitong advanced products go global, smart terminals, intelligent ports, intelligent terminals
22.2.14 -- station B login with code -for circular list form - 'no attribute' - 'needs to be in path selenium screenshot deviation -crop clipping error -bytesio(), etc
The number of incremental paths in the grid graph [dfs reverse path + memory dfs]
my. INI file not found
G1 garbage collector of garbage collector
12、 Service management
随机推荐
[untitled]
Getting started with JDBC
[Godot] add menu button
Have you learned the correct expression posture of programmers on Valentine's day?
Transformer T5 model read slowly
Image 24 bits de profondeur à 8 bits de profondeur
Mysql45 lecture learning notes (II)
[combinatorics] dislocation problem (recursive formula | general term formula | derivation process)*
FBI 警告:有人利用 AI 换脸冒充他人身份进行远程面试
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
Software development freelancer's Road
Enterprise custom form engine solution (12) -- form rule engine 2
Zero length array
This diversion
204. Count prime
The vscode code is automatically modified to a compliance code when it is formatted and saved
编程中常见的 Foo 是什么意思?
多媒体NFT聚合平台OKALEIDO即将上线,全新的NFT时代或将来临
Coordinate layer conversion tool (video)
[combinatorics] generating function (positive integer splitting | repeated ordered splitting | non repeated ordered splitting | proof of the number of repeated ordered splitting schemes)