Leetcode 11. Container With Most Water The Solution of Python
来源:互联网 发布:mac 安装sass 编辑:程序博客网 时间:2024/06/06 21:39
Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water.
Note: You may not slant the container and n is at least 2.
Python:
class Solution(object): def maxArea(self, height): """ :type height: List[int] :rtype: int """ i,j,Max=0,len(height)-1,0 #用来定义最大盛水量的两板位置和水量 while i!=j: if height[i]>=height[j]:#计算每一次的水量,并移动短板 mid,j=(j-i)*height[j],j-1 else: mid,i=(j-i)*height[i],i+1 Max=max(Max,mid)#用max存放最大水量 return Max
容器的水量由最短板和两板距离决定,可行的方法是计算任意两板的盛水量,但是这样太冗余,因此按上述算法来计算。
0 0
- Leetcode 11. Container With Most Water The Solution of Python
- [LeetCode] Container With Most Water, Solution
- [leetcode: Python]11. Container With Most Water
- 【LeetCode with Python】 Container With Most Water
- Leetcode -- Python --Container With Most Water
- 【LeetCode】【Python题解】Container with most water
- 10.Container With Most Water Leetcode Python
- 【LEETCODE】11-Container With Most Water [Python]
- 【leetcode】Container with most water--python实现
- Container With Most Water Leetcode Python Java
- [Leetcode] Container With Most Water Python
- 【Leetcode】【python】Container With Most Water
- LeetCode #11 Container With Most Water C# Solution
- 11. Container With Most Water leetcode Python 2016 new Season
- python写算法题:leetcode: 11. Container With Most Water
- LeetCode 11. Container With Most Water (Python)
- LeetCode 11. Container With Most Water
- [LeetCode]11.Container With Most Water
- 初学php连接mysql (loading)
- 排序算法总结(二)
- C# 连接Oracle 11g,(注:可少走弯路)
- POJ3673Cow Multiplication(水)
- LeetCode-273. Integer to English Words
- Leetcode 11. Container With Most Water The Solution of Python
- 装船问题
- jquery常用事件
- 515. Find Largest Value in Each Tree Row
- C++ 多继承和虚继承的内存布局
- linux下nfs配置
- myeclipse最常用的快捷键
- 欢迎使用CSDN-markdown编辑器
- Android开源库和项目