题目描述
输入输出格式
代码段
数组输入转化成向量解决
#include <iostream>
#include<vector>
using namespace std;
int maxArea(vector<int>& height) {
int l = 0, r = height.size() - 1;
int area=0,ans = 0;
while (l < r) {
area = min(height[l], height[r]) * (r - l);
ans = max(ans, area);
if (height[l] <= height[r]) {
++l;
}
else {
--r;
}
}
return ans;
}
int main()
{
int n;
cin>>n;
int b[1001];
for(int i=0; i<n; i++)
{
cin>>b[i];
}
vector<int> height(b,b+n);
cout<<maxArea(height);
return 0;
}