-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path84.cpp
More file actions
executable file
·23 lines (23 loc) · 805 Bytes
/
84.cpp
File metadata and controls
executable file
·23 lines (23 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class Solution {
public:
int largestRectangleArea(vector<int>& heights) {
if (heights.size() == 0)
return 0;
cout<<heights.size()<<endl;
int minumum = INT_MIN;
for (int i = 0; i < heights.size(); i++) {
int left = i;
int right = i;
while (left > 0 && heights[left] >= heights[i]) left--;
if (heights[left] < heights[i]) left++;
while (right < heights.size()-1 && heights[right] >= heights[i]) right++;
if (heights[right] < heights[i]) right--;
int current_area = (right-left+1)*heights[i];
if (current_area > minumum){
cout<<left<<" "<<right<<endl;
minumum = current_area;
}
}
return minumum;
}
};