题目



题解
暴力解
int maxArea(vector<int>& height) {
int n = height.size();
int max = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int area = std::min(height[i], height[j]) * (j – i);
max = std::max(area, max);
}
}
return max;
}
双指针

class Solution {
public:
int maxArea(vector<int>& height) {
int max = 0;
int l = 0,r = height.size()-1;//两个指针
while(l < r){
int area = std::min(height[l],height[r]) * (r-l);
max = std::max(max,area);
//短的向长的移动
if(height[l] < height[r]) l++;
else r–;
}
return max;
}
};


![P11246 [GESP202409 六级] 小杨和整数拆分-171主机测评](https://www.171host.com/wp-content/uploads/2026/11/20261108100631-6af049a75855c-220x150.png)
![打卡信奥刷题(3678)用C++实现信奥题 P12274 [蓝桥杯 2024 国 Python B] 设计-171主机测评](https://www.171host.com/wp-content/uploads/2026/11/20261108053830-6af00ad6bdf8d-220x150.png)

