Maximal Rectangle
来源:互联网 发布:免费广告录音软件 编辑:程序博客网 时间:2024/05/16 07:10
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and return its area.
class Solution {public: int maximalRectangle(vector<vector<char>>& matrix) { int m = matrix.size(); if(!m) return 0; int n = matrix[0].size(); if(!n) return 0; vector<int> height(n + 1, 0); stack<int> st; int maxArea = 0; for(int i = 0; i < m; ++i) { while(!st.empty()) st.pop(); for(int j = 0; j < n; ++j) height[j] = matrix[i][j] == '0' ? 0 : height[j] + 1; for(int j = 0; j <= n; ++j) { if(st.empty() || height[j] >= height[st.top()]) st.push(j); else { int temp = st.top(); st.pop(); maxArea = max(maxArea, height[temp] * (st.empty() ? j : j - st.top() - 1)); j--; } } } 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
- maven 自动下载jar文件
- 矩阵的几何意义
- Postman 编辑和发送Cookie
- ABAP常用系统变量
- Hadoop安装配置
- Maximal Rectangle
- UIKit各类Object继承关系
- 玩转html5(四)----使用canvas画一个时钟
- 延时动画方法
- 程序的内存布局
- mathtype批量修改公式的字体大小
- Aspose.words编程指南之DocumentBuilder二
- API Hook完全手册
- Android系统启动流程