1 Star 0 Fork 0

libow-python / python_leetcode

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
maxarea.py 544 Bytes
一键复制 编辑 原始数据 按行查看 历史
libor-go 提交于 2021-12-21 13:39 . leetcode
def maxArea(height) -> int:
left = 0
right= len(height) - 1
max_area = 0
while left < right:
if height[left] < height[right]:
area = height[left] * (right-left)
max_area = max(area, max_area)
left += 1
elif height[left] >= height[right]:
area = height[right] * (right-left)
max_area = max(area, max_area)
right -= 1
return max_area
if __name__ == '__main__':
print(maxArea([1, 8, 6, 2, 5, 4, 8, 3, 7]))
print(maxArea([1,2,1]))
1
https://gitee.com/libow-python/python_leetcode.git
git@gitee.com:libow-python/python_leetcode.git
libow-python
python_leetcode
python_leetcode
master

搜索帮助