当前位置:网站首页>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
边栏推荐
- An academic paper sharing and approval system based on PHP for computer graduation design
- Suffix derivation based on query object fields
- Golang string (string) and byte array ([]byte) are converted to each other
- Boost. Asio Library
- Computer graduation design PHP makeup sales Beauty shopping mall
- Shell script return value with which output
- What does foo mean in programming?
- Coordinate layer conversion tool (video)
- Why can deeplab v3+ be a God? (the explanation of the paper includes super detailed notes + Chinese English comparison + pictures)
- Torch learning notes (6) -- logistic regression model (self training)
猜你喜欢

2022-2028 global plasmid DNA cdmo industry research and trend analysis report

CV in transformer learning notes (continuously updated)

Real time split network (continuous update)

Data analysis is popular on the Internet, and the full version of "Introduction to data science" is free to download

12、 Service management
![Bloom filter [proposed by bloom in 1970; redis cache penetration solution]](/img/f9/27a75454b464d59b9b3465d25fe070.jpg)
Bloom filter [proposed by bloom in 1970; redis cache penetration solution]

Prototype inheritance..

2022-2028 global scar care product industry research and trend analysis report

组策略中开机脚本与登录脚本所使用的用户身份

How to expand the capacity of golang slice slice
随机推荐
How about the Moco model?
2022-2028 global scar care product industry research and trend analysis report
Torch learning notes (5) -- autograd
After the festival, a large number of people change careers. Is it still time to be 30? Listen to the experience of the past people
Getting started with JDBC
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
[combinatorics] generating function (positive integer splitting | repeated ordered splitting | non repeated ordered splitting | proof of the number of repeated ordered splitting schemes)
Recommend a simple browser tab
What kind of experience is it when the Institute earns 20000 yuan a month?
Prototype inheritance..
[combinatorics] generating function (use generating function to solve the number of solutions of indefinite equation)
Transformer T5 model read slowly
Suffix derivation based on query object fields
Database creation, addition, deletion, modification and query
[combinatorics] exponential generating function (concept of exponential generating function | permutation number exponential generating function = combinatorial number ordinary generating function | e
论文阅读 GloDyNE Global Topology Preserving Dynamic Network Embedding
Caddy server agent
Torch learning notes (2) -- 11 common operation modes of tensor
Graduation summary
Unity webgl optimization