当前位置:网站首页>leetcode:11. 盛最多水的容器【雙指針 + 貪心 + 去除最短板】
leetcode:11. 盛最多水的容器【雙指針 + 貪心 + 去除最短板】
2022-07-03 18:39: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
總結
雙指針貪心去除最短板
边栏推荐
- 198. Looting - Dynamic Planning
- ES7 - Optimization of promise
- 2022-2028 global scar care product industry research and trend analysis report
- What is the function of registering DLLs- What does registering a DLL do?
- An academic paper sharing and approval system based on PHP for computer graduation design
- Caddy server agent
- English grammar_ Adjective / adverb Level 3 - multiple expression
- 2022-2028 global solid phase extraction column 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)
- English grammar_ Noun classification
猜你喜欢

NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon

Have you learned the correct expression posture of programmers on Valentine's day?

2022-2028 global aircraft head up display (HUD) industry research and trend analysis report

Implementation of cqrs architecture mode under Kratos microservice framework

How to expand the capacity of golang slice slice

Raft log replication

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
![How to read the source code [debug and observe the source code]](/img/87/3cb25eb0301dc8046e39b997411e59.jpg)
How to read the source code [debug and observe the source code]

Grammaire anglaise Nom - Classification

Recommend a simple browser tab
随机推荐
Class exercises
198. Looting - Dynamic Planning
[Yu Yue education] theoretical mechanics reference materials of Shanghai Jiaotong University
English语法_形容词/副词3级 - 倍数表达
Usage of laravel conditional array in
English grammar_ Noun classification
[combinatorics] generating function (use generating function to solve the combination number of multiple sets R)
Computer graduation design PHP sports goods online sales system website
Pan for in-depth understanding of the attention mechanism in CV
2022-2028 global lithium battery copper foil industry research and trend analysis report
MySQL duplicate check
Enterprise custom form engine solution (12) -- form rule engine 2
TypeScript 官网教程
Implementation of cqrs architecture mode under Kratos microservice framework
041. (2.10) talk about manpower outsourcing
Setinterval CPU intensive- Is setInterval CPU intensive?
2022-2028 global solid phase extraction column industry research and trend analysis report
[combinatorics] exponential generating function (proving that the exponential generating function solves the arrangement of multiple sets)
Summary and Reflection on the third week of winter vacation
Sensor debugging process