Py3 C++ C 2pointer速解Leetcode 11Container With Most Water
[Py3 code請進]
[codes on Leetcode]https://leetcode.com/problems/container-with-most-water/solutions/7246605/greedy-2-pointer-beats-100/
[sliding window/ 2-pointer playlist]https://www.youtube.com/watch?v=pi1XpQU_Yxo&list=PLYRlUBnWnd5KrCfs7qCFb-Bvn7dvnakFy
class Solution:
def maxArea(self, h: List[int]) -> int:
n=len(h)
A, l, r=0, 0, n-1
while l < r:
A=max(A, min(h[l], h[r])*(r-l))
if h[r] < h[l]: r-=1
else: l+=1
return A
沒有留言:
張貼留言