public:
int largestRectangleArea(vector<int>& height) {
stack<int> index;
vector<int> high=height;
int result=0;
int temp;
high.push_back(0);
for(int i=0;i<high.size();i++)
{
if(index.empty()||(!index.empty()&&high[i]>=high[index.top()]))
{
index.push(i);
continue;
}
while(!index.empty()&&high[index.top()]>high[i])
{
int idx=index.top();
index.pop();
int width=(index.empty()?i:i-index.top()-1);//The most important line
result=max(result,width*high[idx]);
}
index.push(i);
}
return result;
}
};