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 ...
随机推荐
- Java 使用UDP传输一个小文本文件
工具1:Eclipse 工具2:IntelliJ IDEA Java工程的目录结构(基于IntelliJ IDEA) 例1.1:接收方,因为接收到的数据是字节流,为了方便,这里是基于Apache co ...
- Croppie -一个Javascript图像Croppie
下载 Croppie -一个Javascript图像CroppieCroppie -一个Javascript图像Croppie 安装 凉棚:凉棚安装作物 Npm: Npm安装作物 下载: croppi ...
- Centos 6.9 安装 php5.6
1.检查当前安装的PHP包 yum list installed | grep php 如果有安装的PHP包,先删除他们, 如: yum remove php.x86_64 php-cli.x86_6 ...
- CentOS7 执行 service iptables save 报错 The service command supports only basic LSB actions xxxxxx
现象描述 在 CentOS 7.6.1810 下执行 service iptables save 命令,出现如下错误: [root@test ~]# service iptables save The ...
- background-size 详解
backgroun-size:cover; .是按照等比缩放铺满整个区域.主要用于图片比div小的时候,将图片按照某一边的比例扩大以填充整个div背景. .优点:图片不会被拉升,且实用于div长度和宽 ...
- 如何win10 上访问虚拟机(linux)上redis方法
上一回linux上安装了redis,but在window上面连接不上/??? 配置了密码,不行, 防火墙端口打开了也不行??? 1. 首先要修改redis 的配置文件,找到bind节点,修改bind的 ...
- Python数据类型--列表(list)
Python中列表对应的表示形式是"[]".列表中的元素可以是任何数据类型. 本文以List=[i for i in range(20)]为例进行论述:等价于List=[0, 1, ...
- jvm堆内存和GC简介
最近经常遇到jvm内存问题,觉得还是有必要整理下jvm内存的相关逻辑,这里只描述jvm堆内存,对外内存暂不阐述. jvm内存简图 jvm内存分为堆内存和非堆内存,堆内存分为年轻代.老年代,非堆内存里只 ...
- JVM系列【6】GC与调优1
JVM系列笔记目录 虚拟机的基础概念 class文件结构 class文件加载过程 jvm内存模型 JVM常用指令 GC与调优 GC基础知识 什么是垃圾 没有任何引用指向的一个对象或多个对象(循环引 ...
- localhost与127.0.0.1与0.0.0.0
localhost localhost其实是域名,一般系统默认将localhost指向127.0.0.1,但是localhost并不等于127.0.0.1,localhost指向的IP地址是可以配置的 ...