# 主題:Container With Most Water
---
###### tags: `leetcode`
##### 整理:衡安
---
## 題目大要:
You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]).
Find two lines that together with the x-axis form a container, such that the container contains the most water.
Return the maximum amount of water a container can store.
---
## 解法(演算法):
Two pointer
---
## 程式碼(C++)
```c=
class Solution {
public:
int maxArea(vector<int>& height) {
int l = 0;
int r = height.size()-1;
int res = 0;
while(l<r){
int vol = (r-l)*min(height[l],height[r]);
if(height[l]>=height[r]){
r-=1;
}
else{
l+=1;
}
res = max(res,vol);
}
return res;
}
};
```