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 ...
随机推荐
- 【学习笔记】Polya定理
笔者经多番周折终于看懂了\(\text{Burnside}\)定理和\(\text{Polya}\)定理,特来写一篇学习笔记来记录一下. 群定义 定义:群\((G,·)\)是一个集合与一个运算·所定义 ...
- 小白使用Hystrix
Hystrix是什么东西?百度一下: 没错,hystrix是豪猪的意思,作为SpringCloud微服务系统中保持服务稳定的重要组件,正如它的名字一样,它对整个系统起到了保护的作用. 在许多文章当中把 ...
- Linux系统常用API总结
1.错误处理 - fprintf() - perror() 2.通用I/O模型 - fd = open(pathname, flags, mode) - numread = read(fd, buff ...
- 新手学习C/C++编程过程中常见的那些坑,一定要多多注意!
C/C++中的指针让程序员有了更多的灵活性,但它同时也是一把双刃剑,如果用的不好,则会让你的程序出现各种各样的问题,有人说,C/C++程序员有一半的工作量是花在处理由指针引起的bug上,可想而知,指针 ...
- .NET Core+MongoDB集群搭建与实战
目录 安装 MongoDB apt 直接安装(方法1) apt 仓库安装(方法2) 方法1.2启动 MongoDB 通过二进制包安装(方法3) 安装依赖 deb 安装 MongoDB tgz 安装 M ...
- docker的常用操作之三:网络配置
一, docker安装后容器使用哪些网络类型? 在宿主机执行如下命令: [root@localhost liuhongdi]# docker network ls NETWORK ID NAME DR ...
- centos8平台安装ansible2.9
一,ansible的用途: ansible是基于python开发的自动化运维工具, 它基于SSH远程连接服务, 可以实现批量系统配置.批量软件部署.批量文件拷贝.批量运行命令等多个运维功能 因为基于s ...
- flink 处理实时数据的三重保障
flink 处理实时数据的三重保障 window+watermark 来处理乱序数据对于 TumblingEventTimeWindows window 的元数据startTime,endTime 和 ...
- flutter——android报错建议Suggestion: add 'tools:replace="android:label"'
问题: 安装了一个新包,android出现了报错,建议add 'tools:replace="android:label"'. 原因: 项目application的label属性冲 ...
- 一个例子"入坑"布谷鸟算法(附完整py代码)
布谷鸟是比较新的启发式最优化算法,但其与传统的遗传算法,退火算法等相比,被证明收敛速度更快,计算效率更高! 文章目录 本文诞生的缘由 布谷鸟算法思想简介 更新位置的方式 莱维飞行 局部随机行走 抛出个 ...