--- image: https://leetcode.com/static/images/LeetCode_Sharing.png tags: leetcode --- # Week.3.MID [11. Container With Most Water] --- - 兩個index中選矮的乘以距離, 就是maxArea --- - 雙指針往中央移動, 跟前一結果比大的 - 紀錄最大值 --- ```python! class Solution: def maxArea(self, height: List[int]) -> int: # 兩個index中選矮的乘以距離, 就是maxArea # 雙指針往中央移動, 跟前一結果比大的 # 紀錄最大值 res = 0 # 指標從最小最大邊緣開始 p1,p2 = 0, len(height)-1 # 兩個指標移動到結束 while p1 < p2: # 每次跟前次比較大小 res = max(res, min(height[p1],height[p2])*(p2-p1) ) # 數字小的移動pointer if height[p1] < height[p2]: p1 += 1 else: p2 -= 1 return res ``` [11. Container With Most Water]:https://leetcode.com/problems/container-with-most-water/
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up