Maximal Rectangle
来源:互联网 发布:逗号,在c语言里是什么 编辑:程序博客网 时间:2024/05/17 07:06
public class Solution { public int maximalRectangle(char[][] matrix) { if (matrix == null || matrix.length == 0 || matrix[0].length == 0) { return 0; } int r = matrix.length, c = matrix[0].length; int[][] heights = new int[r][c]; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { if (i == 0) { heights[i][j] = matrix[i][j] - '0'; } else { if (matrix[i][j] != '0') { heights[i][j] = 1 + heights[i - 1][j]; } } } } int maxArea = 0; for (int i = 0; i < r; i++) { Stack<Integer> stack = new Stack<>(); for (int j = 0; j < c; j++) { if (stack.isEmpty()) { stack.push(j); } else { //int h = heights[i][stack.peek()]; while (!stack.isEmpty() && heights[i][j] < heights[i][stack.peek()]) { //int maxH = stack.pop(); int maxH = heights[i][stack.pop()]; if (!stack.isEmpty()) { maxArea = Math.max(maxArea, (j - 1 - stack.peek())*maxH); } else { maxArea = Math.max(maxArea, (j)*maxH); } } stack.push(j); } } while (!stack.isEmpty()) { int h = heights[i][stack.pop()]; if (!stack.isEmpty()) { maxArea = Math.max(maxArea, (c - 1 - stack.peek())*h); } else { maxArea = Math.max(maxArea, c*h); } } } return maxArea; }}
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
- 基于NX的研发产品设计管理平台实现(十八)-物料描述自动提取3
- 反射学习笔记
- QT5.6升级到5.7之后,编译apk失败的解决方案
- C/C++的mem函数和strcpy函数的区别和应用
- Palindrome Linked List
- Maximal Rectangle
- H-Index
- Reverse Nodes in k-Group
- android页面跳转传值
- B001-Atmega16-汇编-地址空间分配
- linux内存源码分析 - 内存回收(整体流程)
- Java进阶(五)Java I/O模型从BIO到NIO和Reactor模式
- iptables配置
- 浅谈 HTTPS 和 SSL/TLS 协议的背景与基础