双指针法
#include<iostream>
#include<vector>
#include "pch.h"
using namespace std;
class Solution {
public:
int maxArea(vector<int>& height) {
int length = height.size();
int left = 0;
int right = length - 1;
int result = 0;
while (left != right)
{
int temp_result = 0;
if (height[left] < height[right])
{
temp_result = height[left] * (right - left);
left++;
}
else
{
temp_result = height[right] * (right - left);
right--;
}
result = (temp_result>result)? temp_result:result;
}
return result;
}
};