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 ...
随机推荐
- Android作业10/07
1.多个Activity界面实现数据的传递 <?xml version="1.0" encoding="utf-8"?> <androidx. ...
- 为Android(和其他移动平台)安装MoSync
为Android(和其他移动平台)安装MoSync Android教程比赛 这是我提交的文章#2:设置你的Android开发环境.它的主要区别在于它描述了如何安装MoSync,这是一种开发环境,它不是 ...
- 树型大融合——NOIP提高组2015 D1T3 【运输计划】
下午用一个小时看了一下树上差分,打了个差分模板,A了3题,真的爽! 题目描述: 公元2044 年,人类进入了宇宙纪元. L 国有 n 个星球,还有 n-1 条双向航道,每条航道建立在两个星球之间,这 ...
- Oracle 按不同时间分组统计
1.按年 select to_char(record_date,'yyyy'), sum(col_8) as total_money from table_name where group by to ...
- ubuntu1804 snort base
1.环境准备 apt安装 sudo apt-get update -y sudo apt-get dist-upgrade -y sudo apt-get install -y zlib1g-dev ...
- 有感于“U盘型人才”
先转载一篇互联网上转载比较多的一篇文章,文章是一名职业规划师写的: 上一阶段欠的债,下一阶段总要还,剩男剩女的家里比较着急也是这个道理,该结婚的时候不结婚,生涯任务没完成,必将影响下一段 ...
- CSS精灵图与字体图标
CSS精灵图与字体图标 1. 精灵图 当用户访问一个网站时,需要向服务器发送请求,网页上的每张图像都要经过一次请求才能展现给用户.然而,一个网页中往往会应用很多小的背景图像作为修饰,当网页中的图像过多 ...
- MeteoInfoLab脚本示例:站点填图
打开包含站点填图的站点数据文件(比如micaps 1)之后,用文件对象的smodeldata函数获取StationModel数据对象,然后用stationmodel函数绘制站点填图图层.脚本程序: # ...
- EV加密播放器的分析过程+过虚拟机方法
开启了OD载入播放器进行分析,发现如下问题:1.播放器会进行翻录检测2.防止虚拟机播放3.视频播放后,可直接对内存操作提取出源视频翻录检测:主要是对指定的文件名或进程名对比虚拟机检测:是针对虚拟机特征 ...
- allure安装
allure是一个通用的测试报告框架 下载地址:http://allure.qatools.ru/ 第一步:进入该页面,右上角有个download,点击进入github页面,选择最新版本下载到某个路径 ...