题解 | #盛水最多的容器#
盛水最多的容器
https://www.nowcoder.com/practice/3d8d6a8e516e4633a2244d2934e5aa47
class Solution { public: //双指针算法 int maxArea(vector<int>& height) { int n=height.size(); int left=0,right=n-1; int res=0; while(left<right) { int v=min(height[left],height[right])*(right-left); res=max(v,res); if(height[right]>height[left])left++; else right--; } return res; } };