思路:

分别按行拆分后将这一行之前的每列叠加起来,然后使用leetcode84https://www.cnblogs.com/wangyiming/p/9620942.html的思路计算。

实现:

 #include <bits/stdc++.h>
using namespace std; class Solution
{
public:
int maximalRectangle(vector<vector<char>>& matrix)
{
int n = matrix.size(); if (n == ) return ;
int m = matrix[].size(); if (m == ) return ;
int ans = ;
vector<int> h(m, ), l(m, ), r(m, );
for (int i = ; i < n; i++)
{
for (int j = ; j < m; j++)
{
h[j] = (matrix[i][j] == '' ? : h[j] + );
}
stack<int> s;
for (int j = ; j < m; j++)
{
while (!s.empty() && h[s.top()] >= h[j]) s.pop();
l[j] = (s.empty() ? : s.top() + );
s.push(j);
}
while (!s.empty()) s.pop();
for (int j = m - ; j >= ; j--)
{
while (!s.empty() && h[s.top()] >= h[j]) s.pop();
r[j] = (s.empty() ? m - : s.top() - );
s.push(j);
}
for (int j = ; j < m; j++)
{
ans = max(ans, (r[j] - l[j] + ) * h[j]);
}
}
return ans;
}
};
int main()
{
char a[][] = {{'','','','',''},
{'','','','',''},
{'','','','',''},
{'','','','',''}};
// char a[][4] = {{'1','1','1','1'},
// {'1','1','1','1'},
// {'1','1','1','1'}};
vector<vector<char>> v;
for (int i = ; i < ; i++)
{
v.push_back(vector<char>(a[i], a[i] + ));
}
cout << Solution().maximalRectangle(v) << endl;
return ;
}

leetcode85 Maximal Rectangle的更多相关文章

  1. LeetCode85 Maximal Rectangle java题解

    public static int maximalRectangle(char[][] matrix) { int rowNum=matrix.length; if(rowNum==0) return ...

  2. 85. Maximal Rectangle

    85. Maximal Rectangle Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle c ...

  3. 求解最大矩形面积 — leetcode 85. Maximal Rectangle

    之前切了道求解最大正方形的题,题解猛戳 这里.这道题 Maximal Rectangle 题意与之类似,但是解法完全不一样. 先来看这道题 Largest Rectangle in Histogram ...

  4. 【leetcode】Maximal Rectangle

    Maximal Rectangle Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle conta ...

  5. [LintCode] Maximal Rectangle 最大矩形

    Given a 2D boolean matrix filled with False and True, find the largest rectangle containing all True ...

  6. 47. Largest Rectangle in Histogram && Maximal Rectangle

    Largest Rectangle in Histogram Given n non-negative integers representing the histogram's bar height ...

  7. leetcode Maximal Rectangle 单调栈

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4052721.html 题目链接:leetcode Maximal Rectangle 单调栈 ...

  8. leetcode面试准备: Maximal Rectangle

    leetcode面试准备: Maximal Rectangle 1 题目 Given a 2D binary matrix filled with 0's and 1's, find the larg ...

  9. 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 ...

随机推荐

  1. AngularJS(Part 10)--页面导航

    页面导航     过去,一个URL代表一个页面.但是随着Ajax的兴起,情况发生的很大的变化.不同的内容可以使用同一个URL.这让浏览器中的回退.前进甚至收藏按钮都失去了作用.而AngularJS提供 ...

  2. [原创]SQL表值函数:获取从当月计算起往前自定义月份数

      今天我现在发现看一篇博文不能够太长,只要能够描述清楚自己想表达的东西,能够让大家知道你要讲什么就行了.因为我今天看了一些长篇博文,真的觉得知识点太多了, 会让人囫囵吞枣. 这篇博文跟我昨天发表的类 ...

  3. Spring IOP 没用

    Spring提供了很多轻量级应用开发实践的工具集合,这些工具集以接口.抽象类.或工具类的形式存在于Spring中.通过使用这些工具集,可以实现应用程序与各种开源技术及框架间的友好整合.比如有关jdbc ...

  4. GCC源码编译

    1. gcc源码下载 ftp://gcc.gnu.org/pub/gcc/releases/ [yhwang@yhwang ~] wget ftp://gcc.gnu.org/pub/gcc/rele ...

  5. python+selenium UI自动化不同浏览器之间的切换

    class register(): ROBOT_LIBRARY_SCOPE = 'GLOBAL' def __init__(self): pass # m默认打开chrome def open_bro ...

  6. 6.7 通过终端连接jboss,连接数据库

    进入终端,通过 ssh jboss@ip地址即可. 然后通过sqlplus 数据库名,输入密码,即可连接数据库. 具体不懂的可以查看对应文档进行操作.

  7. hdu1059

    #include <stdio.h> #include <string.h> #define MAXN 120005 int main() { int num[7]; int ...

  8. windows配置换行符

    CR.LF.CR/LF为不同操作系统上使用的换行符: Windows/DOS系统:采用CR/LF表示下一行: Unix/Linux系统:采用LF表示下一行: Mac OS系统:采用CR表示下一行: M ...

  9. 【eclipse-js验证】

    第一步:去除eclipse的JS验证:将windows->preference->Java Script->Validator->Errors/Warnings->Ena ...

  10. 【linux学习-centeros】

    1:linux的目录结构: / root —?启动Linux时使用的一些核心文件.如操作系统内核.引导程序Grub等. home —?存储普通用户的个人文件 ftp — 用户所有服务 httpd sa ...