84. 柱状图中最大的矩形
两个星期没写leetcode就连暴力解法都写不出了。
暴力解法
class Solution { public: int largestRectangleArea(vector<int>& heights) { int size=heights.size(),maxSize=0; for(int i=0;i<size;i++) { int left=i,right=i; while(left>=1&&heights[left-1]>=heights[i]) left--; while(right<=size-2&&heights[right+1]>=heights[i]) right++; maxSize = max(maxSize,(right-left+1)*heights[i]); } return maxSize; } };
标签:right,int,leetcode84,maxSize,heights,柱状图,矩形,left From: https://www.cnblogs.com/uacs2024/p/16769294.html