11. Container With Most Water
来源:互联网 发布:linux下多线程机制 编辑:程序博客网 时间:2024/06/09 21:02
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.
好水的一道题,结果我想多了,还想用区间dp23333333,思路就是一个简单贪心,其实也有想过贪心,不过方向不对,哎233333
class Solution {public: int maxArea(vector<int>& height) { int len = height.size(); int maxx = 0; int l = 0; int r = len - 1; while(l < r) { maxx = max(maxx, min(height[l], height[r]) * (r - l)); if(height[l] < height[r]) l++; else r--; } return maxx; }};
0 0
- 11.Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11.Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- 11. Container With Most Water
- Spark算子:RDD键值转换操作(4)–cogroup/join
- JavaScript判断浏览器版本(未测试)
- <Python进阶读书笔记>之(五) 条件表达式
- JUnit4 基本用法实例
- git push常用命令
- 11. Container With Most Water
- sql---distinct函数用法
- 如何使用rem单位
- bzoj2115
- jQuery实现的进度条效果(未测试)
- Rightmost Digit
- Android富文本编辑器RichEditor的使用
- ios developer tiny share-20160721
- sizeof用法总结