11. Container With Most Water LeetCode
来源:互联网 发布:ubuntu如何使用cd命令 编辑:程序博客网 时间:2024/05/02 01:22
题意:有n个位置,给出每个位置的高度,选择两个位置和x轴形成贮水池,问贮水池最大面积是多少。
题解:用两个指针往中间移动,每移动一次就算一次面积,直到两个指针相遇,指针如何移动?哪边的高度小,哪边的指针就往中间移动一次。
class Solution {public: int maxArea(vector<int>& height) { int l = 0,r = height.size() - 1; int maxarea = 0; while(l < r) { int h = min(height[l],height[r]); maxarea = max(maxarea,(r - l) * h); if(height[l] < height[r]) l++; else r--; } return maxarea; }};
0 0
- LeetCode 11. Container With Most Water
- [LeetCode]11.Container With Most Water
- LeetCode --- 11. Container With Most Water
- LeetCode 11.Container With Most Water
- [Leetcode] 11. Container With Most Water
- [leetcode] 11.Container With Most Water
- 【leetcode】11. Container With Most Water
- [LeetCode]11. Container With Most Water
- 11. Container With Most Water LeetCode
- leetcode 11. Container With Most Water
- leetcode 11.Container With Most Water
- [LeetCode OJ]11. Container With Most Water
- [leetcode] 11. Container With Most Water
- Leetcode 11. Container With Most Water
- leetcode 11.Container With Most Water
- leetcode 11. Container With Most Water
- LeetCode 11. Container With Most Water
- LeetCode *** 11. Container With Most Water
- 网站复制
- Java认证考试实例疑难辨析(8)
- [MyBatis日记](4)映射语句
- (二)利用processing绘制自定义图像
- C语言中的 (void*)0 与 (void)0
- 11. Container With Most Water LeetCode
- 1032. 挖掘机技术哪家强
- Oracle中session audsid的产生原理及含义
- 【 bzoj 2661 】 [BeiJing wc2012]连连看 - 拆点费用流
- RGW Create bucket
- BZOJ-2190 仪仗队 数论+欧拉函数(线性筛)
- 为图片添加水印图片
- yum 安装常用软件
- 289. Game of Life LeetCode