Reference: "One-day-one-leetcode"
Problem Description:
Note that the container water in the program depends on the small side of the container, not the big side of the container.
Optimizing the Implementation code:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int Maxarea (vector<int> height) {
int i = 0;
Int J = height.size ()-1;
int max = 0;
while (J > i) {
int con = 0;
int min = height[i] > height[j]? HEIGHT[J]: height[i];
if (j = = i + 1) con = min;
else con = min* (j-i);
if (Con > Max) {
max = con;
}
Move the left and right pointers, and note that the smallest we have calculated
if (Height[i] > Height[j]) {
j--
}
else{
i++
}
}
return max;
}
int main () {
vector<int> v;
int arr[] = {3, 4, 5, 6, 9, ten};
for (int i = 0; i < sizeof (arr)/sizeof (arr[0)); i++) {
v.push_back (arr[i]);
int ma = Maxarea (v);
cout << ma << endl;
return 0;
}
Run Result: