# Cool说丨力扣11

+关注继续查看

#### 11. 盛最多水的容器

##### 第一版，速度太慢

int maxArea(vector<int>& height) {

int len=height.size();

int mostWater = 0;

for (int i = 0,row,col; i < len; ++i)

{

for (int j = i+1; j < len; ++j

{

row = j - i;

col = min(height[i], height[j]);

mostWater = row * col > mostWater ? row * col : mostWater;

}

}

return mostWater;

}

##### 第二版 双指针，很快

int maxArea(vector<int>& height) {

int high=height.size()-1,low=0;

int mostWater = 0,temp;

while (low < high)

{

temp = (high - low) * min(height[low], height[high]);

mostWater = mostWater > temp ? mostWater : temp;

if (height[low] <= height[high]) low++;

else high--;

}

return mostWater;

}

##### 官方题解：

https://leetcode-cn.com/problems/container-with-most-water/solution/sheng-zui-duo-shui-de-rong-qi-by-leetcode/

##### 比较经典的介绍

Cool说丨力扣69
[69. x 的平方根](https://leetcode-cn.com/problems/sqrtx/)
16 0
Cool说丨力扣153、454
153. 寻找旋转排序数组中的最小值 454. 四数相加 II
31 0
Cool说丨力扣6
6. Z 字形变换
15 0
Cool说丨力扣29/34

15 0
Cool说丨力扣165
[165. 比较版本号](https://leetcode-cn.com/problems/compare-version-numbers/)
13 0
Cool说丨力扣475
475. 供暖器
22 0
Cool说丨力扣347
[347. 前 K 个高频元素]
15 0
Cool说丨力扣350
[350. 两个数组的交集 II](https://leetcode-cn.com/problems/intersection-of-two-arrays-ii/)
16 0
Cool说丨力扣414与581
414. 第三大的数 581. 最短无序连续子数组
17 0
Cool说丨力扣17
17. 电话号码的字母组合
12 0
+关注
Cool架构