思路:

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

实现:

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. class Solution
  5. {
  6. public:
  7. int maximalRectangle(vector<vector<char>>& matrix)
  8. {
  9. int n = matrix.size(); if (n == ) return ;
  10. int m = matrix[].size(); if (m == ) return ;
  11. int ans = ;
  12. vector<int> h(m, ), l(m, ), r(m, );
  13. for (int i = ; i < n; i++)
  14. {
  15. for (int j = ; j < m; j++)
  16. {
  17. h[j] = (matrix[i][j] == '' ? : h[j] + );
  18. }
  19. stack<int> s;
  20. for (int j = ; j < m; j++)
  21. {
  22. while (!s.empty() && h[s.top()] >= h[j]) s.pop();
  23. l[j] = (s.empty() ? : s.top() + );
  24. s.push(j);
  25. }
  26. while (!s.empty()) s.pop();
  27. for (int j = m - ; j >= ; j--)
  28. {
  29. while (!s.empty() && h[s.top()] >= h[j]) s.pop();
  30. r[j] = (s.empty() ? m - : s.top() - );
  31. s.push(j);
  32. }
  33. for (int j = ; j < m; j++)
  34. {
  35. ans = max(ans, (r[j] - l[j] + ) * h[j]);
  36. }
  37. }
  38. return ans;
  39. }
  40. };
  41. int main()
  42. {
  43. char a[][] = {{'','','','',''},
  44. {'','','','',''},
  45. {'','','','',''},
  46. {'','','','',''}};
  47. // char a[][4] = {{'1','1','1','1'},
  48. // {'1','1','1','1'},
  49. // {'1','1','1','1'}};
  50. vector<vector<char>> v;
  51. for (int i = ; i < ; i++)
  52. {
  53. v.push_back(vector<char>(a[i], a[i] + ));
  54. }
  55. cout << Solution().maximalRectangle(v) << endl;
  56. return ;
  57. }

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. [dp]最长单调递增子序列LIS

    https://www.51nod.com/tutorial/course.html#!courseId=12 解题关键: 如果将子序列按照长度由短到长排列,将他们的最大元素放在一起,形成新序列$B\ ...

  2. C#中的new修饰符说明

    new修饰符主要是用来隐藏从基类继承的成员. 这句话怎么理解呢,就是说有一个类,它有一个继承类,继承类中存在和基类中一样名称的成员(属性,方法等). 对继承类中的该成员使用new修饰符时,调用时将会隐 ...

  3. HDU 3966 Aragorn's Story (简单树链剖分)

    题意:给一棵树,并给定各个点权的值,然后有3种操作: I C1 C2 K: 把C1与C2的路径上的所有点权值加上K D C1 C2 K:把C1与C2的路径上的所有点权值减去K Q C:查询节点编号为C ...

  4. FUI- 我离钢铁侠还差几步?

    本文来自网易云社区 作者:马宝 什么是FUI本文不累赘的可以自行Google,喜欢科幻的同学们都看一张图就能感受到FUI的魅力. 本文算是一篇所见即所的,可边学边干的原创教程.总结全文就一句话,&qu ...

  5. Vue.js 源码实现

    目录 Vue.js 代码实现 1. 步骤一 2. 步骤二 3.步骤三 Vue.js 工作机制 初始化 编译 响应式 虚拟dom 更新视图 编译 Vue.js 代码实现 检验学习效果的最好方法就是自己造 ...

  6. 读《JavaScript权威指南》笔记(二)

    1.加号运算和比较运算符的区别 对于数字和字符串操作符来说,加号运算符和比较运算符的行为都有所不同,前者更偏爱字符串,如果它的其中一个操作数是字符串的话,则进行字符串连接操作.而比较运算符则更偏爱数字 ...

  7. 依托http-headers的 sql注入和时间盲注

    机缘巧合接触了一点关于sql注入的网络安全问题 依托 headers 的 sql 注入 一般来说大家都很清楚用户输入的危险性,通常会对用户表单提交的数据进行过滤(引号转码). 但是如果写过网络爬虫,那 ...

  8. .NET ToString() format格式化字符串(常用)

    前言 我们平常会用到货币数据类型,尤其当我们计算金钱或者算数的时候经常会遇到保留几位小数,而且碰到日期格式问题的时候,经常不知道选择什么样的格式比较合适,下面我找了一部分常用的.NET ToStrin ...

  9. DNS解析工具--nslookup和dig使用

    1.nslookup使用 [root@master ~]# nslookup> server 8.8.8.8    #指定域名服务器Default server: 8.8.8.8Address: ...

  10. mysql之SQL入门与提升(二)

    在mysql之SQL入门与提升(一)我们已经有了些许基础,今天继续深化 先造表 SET NAMES utf8;SET FOREIGN_KEY_CHECKS = 0; -- -------------- ...