leetcode64:maximal-rectangle
题目描述
public:
int maximalRectangle(vector<vector<char> > &matrix) {
if (matrix.size()==0)
return 0;
int m=matrix.size();
int n=matrix[0].size();
vector< int> h(n);
int maxS=0;
int num;
stack<int> st;
st.push(-1);
for (int i=0;i<m;i++)
{
for (int j=0;j<n;j++){
if (matrix[i][j]=='1')
h[j]++;
else
h[j]=0;
}
for (int j=0;j<n;j++){
while (st.top()!=-1 && h[j] <h[st.top()])
{
num=st.top();
st.pop();
maxS=max(maxS,(j-1-st.top())*h[num]);
}
st.push(j);
}
while (st.top()!=-1){
num=st.top();
st.pop();
maxS=max(maxS,(n-1-st.top())*h[num]);
}
}
return maxS;
}
};
leetcode64:maximal-rectangle的更多相关文章
- 85. Maximal Rectangle
85. Maximal Rectangle Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle c ...
- 求解最大矩形面积 — leetcode 85. Maximal Rectangle
之前切了道求解最大正方形的题,题解猛戳 这里.这道题 Maximal Rectangle 题意与之类似,但是解法完全不一样. 先来看这道题 Largest Rectangle in Histogram ...
- 【leetcode】Maximal Rectangle
Maximal Rectangle Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle conta ...
- [LintCode] Maximal Rectangle 最大矩形
Given a 2D boolean matrix filled with False and True, find the largest rectangle containing all True ...
- 47. Largest Rectangle in Histogram && Maximal Rectangle
Largest Rectangle in Histogram Given n non-negative integers representing the histogram's bar height ...
- leetcode Maximal Rectangle 单调栈
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4052721.html 题目链接:leetcode Maximal Rectangle 单调栈 ...
- leetcode面试准备: Maximal Rectangle
leetcode面试准备: Maximal Rectangle 1 题目 Given a 2D binary matrix filled with 0's and 1's, find the larg ...
- LeetCode之“动态规划”:Maximal Square && Largest Rectangle in Histogram && Maximal Rectangle
1. Maximal Square 题目链接 题目要求: Given a 2D binary matrix filled with 0's and 1's, find the largest squa ...
- 最大的矩形面积 Maximal Rectangle
2018-09-15 10:23:44 一.Largest Rectangle in Histogram 在求解最大的矩形面积之前,我们先讨论一条最大直方图面积的问题. 问题描述: 问题求解: 解法一 ...
- 85. Maximal Rectangle (Graph; Stack, DP)
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and ...
随机推荐
- matlab中figure 创建图窗窗口
来源:https://ww2.mathworks.cn/help/matlab/ref/figure.html?searchHighlight=figure&s_tid=doc_srchtit ...
- 使用Jest快照测试api
你知道什么很烦人吗?API不匹配. 有一天,后台开发人员在没有通知前端开发人员的情况下更改了其中一个api."我们认为dateCreated这个名字比created_at更好,"他 ...
- 基于空镜像scratch创建一个新的Docker镜像
我们在使用Dockerfile构建docker镜像时,一种方式是使用官方预先配置好的容器镜像.优点是我们不用从头开始构建,节省了很多工作量,但付出的代价是需要下载很大的镜像包. 比如我机器上docke ...
- RHSA-2017:1931-中危: bash 安全和BUG修复更新(代码执行)
[root@localhost ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) 修复命令: 使用root账号登陆She ...
- ls: 显示目下的内容及相关属性信息
ls: 显示目下的内容及相关属性信息 [功能说明] ls 命令可以理解为英文单词 "list" 的缩写,其功能是列出目录的内容及其内容属性信息(list directory con ...
- Solr单机安装
Solr单机安装 一.下载 自行到官网下载所需版本即可,我这里使用的是solr-7.1.0solr官网:http://archive.apache.org/dist/lucene/solr/ 二.安装 ...
- 多测师讲解接口测试_F12中network里headers各项属性的含义——高级讲师肖sir
General部分: Request URL:资源的请求url # Request Method:HTTP方法 Status Code:响应状态码 200(状态码) OK 301 - 资源(网页等 ...
- 【C语言/C++程序员编程】一小时做出来的数字雨(一颗开花的树)!
相信大家看过许许多多的关于计算机黑客.骇客.人工智能.AI方面的电影,每当黑客入侵某个五角大楼,某个网站时,都会出现这样一副画面: 入侵 或者这样的: 数字雨 然后就轻而易举的成功入侵夺取管理员权限了 ...
- idea创建servlet工程初体验
servlet工程创建 前提:创建项目之前需要配置java环境变量 和tomcat配置,配置完成后进入如下操作. tomcat 安装和配置参考 https://www.cnblogs.com/xush ...
- 用CentOS 7自制Vagrant Box文件
写在前面 利用vagrant保持开发生产环境一致是一个很好的方法,不过vagrant官网上的box文件下载是真的很慢,因此,这里教大家如何自制box文件. 这篇文章你会接触到: vagrant使用 ...