Use stack
class Solution {
public:
int largestRectangleArea(vector<int>& height) {
stack<int> s;
int res=0;
height.push_back(0);
for(int i=0;i<height.size();i++)
{
if(s.empty()||height[i]>=height[s.top()])
s.push(i);
else
{
while(!s.empty()&&height[s.top()]>height[i])
{
int h=height[s.top()];
s.pop();
int w=s.empty()?i:i-s.top()-1;
int area=h*w;
res=area>res?area:res;
}
s.push(i);
}
}
return res;
}
};