本文主要是介绍Python | Leetcode Python题解之第11题盛最多水的容器,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目:
题解:
class Solution:def maxArea(self, height: List[int]) -> int:l, r = 0, len(height) - 1ans = 0while l < r:area = min(height[l], height[r]) * (r - l)ans = max(ans, area)if height[l] <= height[r]:l += 1else:r -= 1return ans
这篇关于Python | Leetcode Python题解之第11题盛最多水的容器的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!