动态规划问题——求解柱形图最大的的矩形面积
初始化: 双指针 low , high分列水槽左右两端;
循环收窄: 直至双指针相遇时跳出;(较小的值向中间靠拢)
更新面积最大值: maxnum ;
选定两板高度中的短板,向中间收窄一格;
返回值: 返回面积最大值 maxnum即可;
class Solution {
public:
int minnum(int a,int b)
{
return a<b?a:b;
}
int maxArea(vector<int>& height) {
int maxnum=0;
int len=height.size();
int low=0;int high=len-1;
while(low<high)
{
int temp=minnum(height[low],height[high])*(high-low);
maxnum=max(maxnum,temp);
if(height[low]<height[high])
low++;
else
high--;
}
return maxnum;
}
};