class Solution {
public:
int largestRectangleArea(vector<int>& heights) {
if (heights.size() == 0) {
return 0;
}
int n = heights.size(), area = INT_MIN;
for (int i = 0; i < n; i++) {
if (i + 1 < heights.size() && heights[i] <= heights[i + 1]) {
continue;
}
int minH = heights[i];
for (int j = i; j >= 0; j--) {
minH = min(minH, heights[j]);
int tmpArea = minH * (i - j + 1);
area = max(area, tmpArea);
}
}
return area;
}
};