classSolution{publicintmaximalRectangle(char[][] matrix){if(matrix ==null|| matrix.length ==0){return0;}// 看成【对每层,进行柱状图最大面积判断】即可(相当于固定底)int max =0;int[] heights =newint[matrix[0].length];for(int i =0; i < matrix.length; i++){for(int j =0; j < matrix[0].length; j++){if(matrix[i][j]=='1'){heights[j]++;}else{heights[j]=0;}}max =Math.max(max,largestRectangleArea(heights));}return max;}// 84. 求柱状图最大矩阵面积publicintlargestRectangleArea(int[] heights){int res =0;Deque<Integer> stack =newArrayDeque<>();int[] newHeights =newint[heights.length +2];for(int i =1; i < heights.length +1; i++){newHeights[i]= heights[i -1];}for(int i =0; i < newHeights.length; i++){while(!stack.isEmpty()&& newHeights[stack.peek()]> newHeights[i]){int index = stack.pop();int l = stack.peek();int r = i;res =Math.max(res,(r - l -1)* newHeights[index]);}stack.push(i);}return res;}}
二刷
思路还是记得的
classSolution{publicintmaximalRectangle(char[][] matrix){if(matrix ==null|| matrix.length ==0)return0;int[] heights =newint[matrix[0].length];int res =0;// 逐行转换for(int i =0; i < matrix.length; i++){// 当前行的逐列维护for(int j =0; j < matrix[0].length; j++){if(matrix[i][j]=='1'){heights[j]++;}else{heights[j]=0;}}res =Math.max(res,largestRectangleArea(heights));}return res;}publicintlargestRectangleArea(int[] heights){int[] newHeights =newint[heights.length +2];for(int i =1; i <= heights.length; i++){newHeights[i]= heights[i -1];}Deque<Integer> stack =newArrayDeque<>();int max =0;for(int i =0; i < newHeights.length; i++){while(!stack.isEmpty()&& newHeights[i]< newHeights[stack.peek()]){int now = stack.poll();int left = stack.peek();int right = i; max =Math.max(max,(right - left -1)* newHeights[now]);}stack.push(i);}return max;}}
ANDRITZ to supply gasification plant and biomass handling line to Klabin’s Puma II project in Brazil.国际技术集团公司安德里茨收到KLabin的订单,为其位于巴西的Ortigueira浆厂提供一台完整的生物质气化炉和一条新的生物质处理线。International technology…