84.柱状图中最大的矩形
- class Solution {
- public:
- int largestRectangleArea(vector<int>& heights) {
- int sum = 0;
- for (int i = 0; i < heights.size(); i++) {
- int left = i;
- int right = i;
- for (; left >= 0; left--) {
- if (heights[left] < heights[i]) break;
- }
- for (; right < heights.size(); right++) {
- if (heights[right] < heights[i]) break;
- }
- int w = right - left - 1;
- int h = heights[i];
- sum = max(sum, w * h);
- }
- return sum;
- }
- };