# LeetCode : 0011. Container With Most Water (array)
###### tags:`leetcode`
```
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <unordered_map>
using std::vector;
using std::unordered_map;
using namespace std;
class BaseVectorPrint {
public:
void BasePrint00(vector<int>& num) {
for (size_t i = 0; i < num.size(); ++i) {
cout << "[" <<num.at(i) << "]" << "; ";
}
cout << endl;
}
void BasePrint01(vector<int>& num) {
for (size_t i = 0; i < num.size(); ++i) {
cout << num[i] << "; ";
}
cout << endl;
}
void BasePrint02(vector<int>& num) {
for (const auto &item : num) {
cout << item << "; ";
}
cout << endl;
}
void TwoDimensionalPrint(vector<vector<int>> &num){
for (int i = 0; i < num.size(); i++)
{
for (int j = 0; j < num[i].size(); j++)
{
cout << "[" << num[i][j] << "]";
}
cout << endl;
}
}
};
class Solution01 {
public:
int maxArea(vector<int>& height) {
int water = 0;
int left = 0, right = height.size() - 1;
while (left < right) {
int h = min(height[left], height[right]);
int l = right - left ;
water = max(water, l * h); //Water Aera lenth * height and min height
while (height[left] <= h && left < right) left++;
while (height[right] <= h && left < right) right--;
}
return water;
}
//Time complexity: O(n) Single pass (only while loop)
//Space complexity: O(1) Constant space is used. (no array , maple , hashtable)
};
int main(void)
{
BaseVectorPrint printVector;
Solution01 runfunc;
vector<int> test01 = { 1,8,6,2,5,4,8,3,7 };
vector<int> test02 = { 1, 2, 3, 4 };
vector<int> test03 = { -1, 1, 0, -3, 3 };
vector<int> ans ;
int Intans ;
Intans = runfunc.maxArea(test01);
//printVector.BasePrint00(ans);
printf("Intans = %d\n",Intans);
printf("test\n");
system("pause");
}
```
> TIP Water Aera = lenth x height x min height