LeetCodemaxarea largest rectangle in a histogram 直方图中最大的矩形
力扣最大面积直方图中最大的矩形给定n个非负整数表示直方图的条形高度,其中每个条形的宽度为1,求直方图中最大矩形的面积。上面是一个直方图,其中每个条的宽度为1,给定高度= [2,1,5,6,2,3]。最大的矩形显示在阴影区域中,其面积= 10单位。实现1:O(n^2) class Solution { public int largestRectangleArea ( int [] heights ) { if (heights == null || heights . length == 0 ) return 0 ; int area = heights[ 0 ]; for ( int i = 0 ; i < heights . length; i ++ ) { int minHeight = heights[i]; area = Math . max(area, heights[i]); for ( int j = i + 1 ; j < heights . length; j ++ ) { minHeight = Math . min(minHeight
用户评论