LeetCode : No11 Container With Most Water
来源:互联网 发布:淘宝网甩棍多少钱一根 编辑:程序博客网 时间:2024/04/30 11:28
题目链接:https://leetcode.com/problems/container-with-most-water/
直接看discuss里面的讨论。。。
The idea is : to compute area, we need to take min(height[i],height[j]) as our height. Thus ifheight[i]<height[j]
, then the expressionmin(height[i],height[j])
will always lead to at maximumheight[i]
for all other j(i being fixed), hence no point checking them. Similarly whenheight[i]>height[j]
then all the other i's can be ignored for that particular j.
耗时:91ms
class Solution: # @return an integer def maxArea(self, height): l = 0 n = len(height) - 1 MAX = 0 while (l < n): MAX = max(MAX, (n-l)*min(height[l],height[n])) if (height[l] < height[n]): temp = height[l] l = l + 1 while (l+1 < n and temp >= height[l]): l = l + 1 else: temp = height[n] n = n - 1 while (l < n-1 and temp >= height[n]): n = n - 1 return MAX
0 0
- LeetCode : No11 Container With Most Water
- leetcode No11. Container With Most Water
- LeetCode: Container With Most Water
- [LeetCode]Container With Most Water
- LeetCode Container With Most Water
- LeetCode: Container With Most Water
- [Leetcode] Container With Most Water
- Leetcode: Container With Most Water
- [LeetCode] Container With Most Water
- LeetCode Container With Most Water
- [Leetcode] Container With Most Water
- [LeetCode]Container With Most Water
- LeetCode-Container With Most Water
- Container With Most Water leetcode
- LeetCode - Container With Most Water
- LeetCode: Container With Most Water
- Leetcode: Container With Most Water
- 【LeetCode】Container With Most Water
- SQL 左外连接,右外连接,全连接,内连接
- Error:Execution failed for task ':app:dexDebug'.finished with non-zero exit value 2
- storyboard简单跳转和数据传值
- wifidog http.c&.h分析
- SpringMVC 注解配置
- LeetCode : No11 Container With Most Water
- error C3861: “InitializeCriticalSectionAndSpinCount”: 找不到标识符
- swift知识点小记
- php中的this self parent
- DOS中SET命令的详细用法
- cocos2d-x 3.3 之卡牌设计 NO.1 点击选取卡牌
- 那些高阅读量文章的标题都是怎么取的?14种模板直接套用
- 编写python安装包
- jms