leetcode——Container With Most Water
来源:互联网 发布:as3.0调用js页面方法 编辑:程序博客网 时间:2024/06/08 16:31
题目:
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 linei 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.
class Solution {public: int maxArea(vector<int>& height) { int i = 0, j = height.size() - 1;//维护两个指针,分别向中间靠拢,更新最大面积 int max_area = 0; while (i < j) { int area = (j - i) * min(height[i], height[j]); max_area = max(area, max_area); if (height[i] < height[j])//每次更新较短的线段,因为更新较大的线段必然造成面积变小 { ++i; } else { --j; } } return max_area; }};
0 0
- 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
- 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——11——Container With Most Water
- leetcode 011 —— Container With Most Water
- LeetCode题解——Container With Most Water
- #11 LeetCode——Container With Most Water
- leetcode第11题——**Container With Most Water
- 【leetcode】Array——Container With Most Water(11)
- LeetCode——11. Container With Most Water
- LeetCode之路——Container With Most Water
- Python爬虫积累
- 【BZOJ 2818】 gcd(附φ的线性筛法预处理)
- 当布局中如果出现多个文本并且颜色背景不同,我们怎么办
- 1、我的php自学笔记开始
- swift 学习这十八:宏()
- leetcode——Container With Most Water
- c++: vector
- 应用内跳转到App Store
- Swift 学习之二十:类型强转(+、-、*、/)
- hdu acm 1016
- wol 远程开机编译源码
- 互联网圈子,黄进磊竟然把它解释的如此霸气!
- windows远程桌面访问ubuntu
- Swift 学习之Using Swift mix and match, network: 写rss阅读器