class Solution {
public:
int largestRectangleArea(vector<int> &height) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if (height.size()==0) return 0;
int max=0;
int current=0;
int width=0;
for (int i=0; i<height.size(); i++) {
current=height[i];
width=1;
int j=i+1;
while (j<height.size()) {
if(height[j]>=current) {
width++;
j++;
}else {
break;
}
}
j=i-1;
while (j>=0) {
if(height[j]>=current) {
width++;
j--;
}else {
break;
}
}
if (current*width>max){
max=current*width;
}
}
return max;
}
};
Largest Rectangle in Histogram
最新推荐文章于 2021-06-11 18:32:21 发布