Leetcode Container With Most Water
来源:互联网 发布:网店数据化分析的内容 编辑:程序博客网 时间:2024/04/30 13:11
Container With Most Water
Total Accepted: 4630 Total Submissions: 15434My SubmissionsGiven 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.
知道原理就是很简单的程序。两边搜索,短板往里走。因为往里走,代表宽度减小,那么宽度小的时候,只有遇上更高的高度才能组成更加大的container。
int maxArea(vector<int> &height) { int area = 0; int i = 0, j = height.size()-1; while (i<j) { area = max(area, (j-i)*min(height[i], height[j])); (height[i] > height[j])? j--:i++; } return area; }
1 0
- 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
- Leetcode: Container With Most Water
- LeetCode:Container With Most Water
- Sql plus命令报command not found的解决笔记
- 老杨的相关博文索引
- C#.net cookie、session实现自动登陆
- Tomcat5发布项目问题(2):默认不解析EL表达式
- 解决XBMC / OpenELEC中文乱码
- Leetcode Container With Most Water
- c++ string c_str()
- <MEMORY>Project Euler NO24
- Search a 2D Matrix
- repo sync 挂起
- Javascript面向对象编程 产生对象
- SRM 605 D2 L2:AlienAndGame
- 爱情公寓
- Word 2003域应用完全手册