Maximal Rectangle
来源:互联网 发布:奔驰换大灯编程教程 编辑:程序博客网 时间:2024/06/11 10:22
Maximal Rectangle
Java代码:
public class Solution { public int maximalRectangle(char[][] matrix) { if (matrix==null||matrix.length==0||matrix[0].length==0) return 0; int cLen = matrix[0].length; // column length int rLen = matrix.length; // row length // height array int[] h = new int[cLen+1]; h[cLen]=0; int max = 0; for (int row=0;row<rLen;row++) { Stack<Integer> s = new Stack<Integer>(); for (int i=0;i<cLen+1;i++) { if (i<cLen) if(matrix[row][i]=='1') h[i]+=1; else h[i]=0; if (s.isEmpty()||h[s.peek()]<=h[i]) s.push(i); else { while(!s.isEmpty()&&h[i]<h[s.peek()]){ int top = s.pop(); int area = h[top]*(s.isEmpty()?i:(i-s.peek()-1)); if (area>max) max = area; } s.push(i); } } } return max; }}
上述代码参考Leetcode官网
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
- 顺序表的实现
- 网页调用ocx的方法
- 这两年比较看好的几个项目
- bootstrap+django快速构建一个blog
- 打造android ORM框架opendroid(二)——自动创建数据库
- Maximal Rectangle
- Laravel大型项目系列教程(三)之发表文章
- apps被拒绝的各种理由以及翻译
- RHEL6使用CentOS6的yum源
- 千里之行,始于足下
- 链表的实现
- 大型网站技术架构
- Ajax方式上传文件
- Sql Having 用法示例