思路:

分别按行拆分后将这一行之前的每列叠加起来,然后使用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. [poj1088]滑雪(二维最长下降子序列)

    解题关键:记忆化搜索 #include<cstdio> #include<cstring> #include<algorithm> #include<cstd ...

  2. Static与Const的区别

    static static局部变量 将一个变量声明为函数的局部变量,那么这个局部变量在函数执行完成之后不会被释放,而是继续保留在内存中 static 全局变量 表示一个变量在当前文件的全局内可访问 s ...

  3. 杭电acm 1049题

    一道水题..... 大意是一条1inch的虫子在一个n inch的盒子的底部,有足够的能够每一分钟往上爬u inch,但是需要休息一分钟,这期间会往下掉d inch,虫子爬到盒子口即认为结束.要求计算 ...

  4. Entity Framework Code-First(6):Database Initialization

    Database Initialization: We have seen that Code First creates a database automatically in the Simple ...

  5. 项目中缺少org.wltea.ik-analyzer如何解决?

    IKAnalyzer是一个开源的,基于java语言开发的轻量级的中文分词工具包.从2006年12月推出1.0版开始,IKAnalyzer已经推出了3个大版本.最初,它是以开源项目Luence为应用主体 ...

  6. 同台电脑 多Git账号同时使用

    前言 有次周末忘记带公司电脑回来,恰好遇到有个问题需要修复,又不想跑公司一趟,于是研究了下如何在自己电脑上同时使用两个 git 账号 正文 1. 首先就和第一次安装 git 时一样,使用 sha算法 ...

  7. C# 写 LeetCode easy #26 Remove Duplicates from Sorted Array

    26.Remove Duplicates from Sorted Array Given a sorted array nums, remove the duplicates in-place suc ...

  8. Bigdecimal 比较equals与compareTo

    原文链接:https://blog.csdn.net/jixinhuluwa/article/details/72626598 1.b.equals(BigDecimal.ZERO); 该方法存在的问 ...

  9. 从技术 Leader 的招聘需求看,如何转岗为当前紧缺的大数据相关人才?

    前段时间,跟候选人聊天的时候,一个有多年工作经验的资深 iOS 工程师告诉我,他最近正在学习 Machine Learning 相关的知识.他觉得,对于程序员来说,技术进步大大超过世人的想象,如果你不 ...

  10. AT2672 Coins

    传送门 按理说想到转化问题之后就不难了吧,可是我还是不会写 一个很容易想到的转化就是差分,将银币数和铜币数都减去金币数,这样就转化为\(x+y+z\)个钱币选\(y\)个银币和\(z\)个铜币的最大数 ...