题目:
题解:
int largestRectangleArea(int* heights, int heightsSize) {int st[heightsSize];int p[2];p[0]=-1,p[1]=heightsSize;int size=0,result=0;st[size++]=0;for(int i=1;i<heightsSize;i++){ while(size!=0&&heights[i]<heights[st[size-1]]){int mid=heights[st[size-1]];int b;if(size-1==0){b=mid*(i-p[0]-1);}else{b=mid*(i-st[size-2]-1);}result=(b>result?b:result);size--;}st[size++]=i;}while(size>0) //此时开始处理栈里面剩下的值{int mid,b;if(size-1!=0){mid=heights[st[size-1]];b=mid*(p[1]-st[size-2]-1);}else{mid=heights[st[size-1]];b=mid*(p[1]-p[0]-1);}result=(b>result?b:result);size--;}return result;
}