CODE 48: Maximal Rectangle
来源:互联网 发布:网络智能电视机顶盒 编辑:程序博客网 时间:2024/06/06 20:43
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.
public int maximalRectangle(char[][] matrix) {// Start typing your Java solution below// DO NOT write main() functionif (null == matrix || matrix.length <= 0) {return 0;}int rows = matrix.length;int cols = matrix[0].length;int[][] vmax = new int[rows][cols];if (matrix[0][0] == '1') {vmax[0][0] = 1;}int maximum = Integer.MIN_VALUE;for (int i = 0; i < rows; i++) {for (int j = 0; j < cols; j++) {if (i == 0) {if (matrix[i][j] == '1') {vmax[i][j] = 1;}} else {if (matrix[i][j] == '1') {vmax[i][j] = 1 + vmax[i - 1][j];} else {vmax[i][j] = 0;}}}}for (int i = rows - 1; i >= 0; i--) {int tmp = largestRectangleArea(vmax[i]);if (tmp > maximum) {maximum = tmp;}}return maximum;}
- CODE 48: Maximal Rectangle
- maximal-rectangle Java code
- leetcode 日经贴,Cpp code -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
- Android 动画学习小结
- HDOJ 4764 - Stone 巴什博弈模板题...
- 各种数字格式化
- Bjarne Stroustrup on the Evolution of Languages
- Longest Consecutive Sequence
- CODE 48: Maximal Rectangle
- 写给自己的操作系统大小端问题
- PM3
- .net技术类面试、笔试题汇总2
- android ExpandableListView详解
- Sum Root to Leaf Numbers
- 微信BAE链接Mysql 数据查询
- hdu 4766 Network 长春网络赛 1008 计算几何
- 小米手机图标消失问题