maximal-rectangle
来源:互联网 发布:linux top命令详解 编辑:程序博客网 时间:2024/06/07 00:09
自己做个笔记用
public class Solution{ public int maximalRectangle(char[][] matrix){ if(matrix==null || matrix.length==0 || matrix[0].length==0) return 0; int[] height = new int[matrix[0].length]; for(int i==0;i<matrix[0].length;i++){ if(matrix[0][i]=="1") height[i]==1; } int result=largestInLine(height); for(int i=1;i<matrix.length;i++){ resetHeight(matrix,height,i); result=Math.max(result,largestInLine(height)); } return result; } //为每行维护的数组,用于储存高度 public int largestInLine(int[] height){ if(height==null || height.length==0) return 0; int len=height.length; Stack<Integer> s=new Stack<Integer>(); int maxArea=0; for(int i=0; i<=len;i++){ int h=(i==len?0:height[i]); if(s.isEmpty() || h>=height[s.peek()]){ s.push(i); }else{ int tp=s.pop(); maxArea=Math.max(maxArea,height[tp]*(s.isEmpty()?i:i-1-s.peek())); i--; } } return maxArea; } //重置高度,用以扫描整个矩阵 private void resetHeight(char[][] matrix,int[] height,int idx){ for(int i=0;i<matrix[0].length;i++){ if(matrix[idx][i]=='1') height[i]+=1; else height[i]=0; } }}
阅读全文
0 0
- Maximal Rectangle
- Maximal Rectangle
- Maximal Rectangle
- Maximal Rectangle
- Maximal Rectangle
- Maximal Rectangle
- Maximal Rectangle
- Maximal Rectangle
- Maximal Rectangle
- Maximal Rectangle
- Maximal Rectangle
- Maximal Rectangle
- Maximal Rectangle
- Maximal Rectangle
- Maximal Rectangle
- Maximal Rectangle
- Maximal Rectangle
- Maximal Rectangle
- 设计模式-迭代器模式 C++实现
- Bootstrap基础的学习
- 排序算法(七):归并排序
- 配置SSM 后 无法访问静态资源
- android 使用注解
- maximal-rectangle
- 七、Spring Cloud系列:让Logback日志中显示主机名与IP地址
- TpsFs文件系统概述(一)
- [SCOI2005]栅栏 二分+dfs
- [模板] 最小费用最大流
- shell命令-find常用命令
- 题目40-公约数和公倍数
- 人数统计 树状数组+离散化
- 56. Merge Intervals