[Leetcode] Container With Most Water 能装最大水的容量
2016-07-15 11:03
423 查看
class Solution { public: int maxArea(vector<int>& height) { int res = 0; int n = height.size(); int l = 0, r = n - 1; while (l < r) { res = max(res, min(height[l], height[r])*(r - l)); if (height[l] < height[r]) { int k = l; while (k<r&&height[k] <= height[l]) k++; l = k; } else { int k = r; while (k>l&&height[k] <= height[r]) k--; r = k; } } return res; } };
相关文章推荐
- 忘记hmailiserver邮件服务器后台登陆密码解决
- 每日Scrum站会实践推荐
- Codeforces 675E Trains and Statistic(DP + 贪心 + 线段树)
- SDK Failed to fetch URL http://dl.google.com/android/repository
- VC6.0 error LNK2001: unresolved external symbol _main解决办法
- hdu1022-Train Problem I
- CodeForces 567A Lineland Mail
- 2015 ACM/ICPC Asia Regional Shanghai Online
- socketpair
- 百度云+AI,人工智能走进场景应用时代
- container_of学习
- Leetcode Factorial Trailing Zeroes
- Leetcode Container With Most Water
- 崩溃定位到main方法里怎么办
- Fairpixels向初创公司开源未被采用的Logo
- 373. Find K Pairs with Smallest Sums
- 杭电 1023 Train Problem II
- UVA 573 The Snail
- MainWindows
- Numpy ConfigParser.MissingSectionHeaderError: File contains no section headers.