11. 盛最多水的容器
This commit is contained in:
16
test005.cpp
Normal file
16
test005.cpp
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
int maxArea(vector<int>& height) {
|
||||||
|
int len = height.size();
|
||||||
|
int l = 0, r = len - 1;
|
||||||
|
int res = 0;
|
||||||
|
|
||||||
|
while(l < r){
|
||||||
|
int area = min(height[l],height[r]) * (r - l);
|
||||||
|
res = max(area, res);
|
||||||
|
if(height[l] > height[r]) r--;
|
||||||
|
else l++;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user