code:

 #include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std; class Solution {
public:
int largestRectangleArea(vector<int> &height) {
height.push_back();
int i = ;
int result = ;
stack<int> s;
while (i < height.size())
{
if (s.empty() || height[i]>height[s.top()])
s.push(i++);
else
{
int tmp = s.top();
s.pop();
result = max(result, height[tmp] * (s.empty() ? i : i - s.top() - ));
}
}
return result;
} int maximalRectangle(vector<vector<char> > &matrix) {
if (matrix.size() == || matrix[].size() == ) return ;
int H = matrix.size(), W = matrix[].size();
int ret = ; int **tmpHeight = new int*[H];
for (int i = ; i < H; i++)
{
tmpHeight[i] = new int[W];
} for (int i = ; i < H; i++)
{
for (int j = ; j < W; j++)
{
if (matrix[i][j] == '')
{
tmpHeight[i][j] = ;
}
else
{ tmpHeight[i][j] = (i == ? : tmpHeight[i - ][j] + );
}
}
}
for (int i = ; i < H; i++)
{
vector<int> vtmp(tmpHeight[i], tmpHeight[i] + W);
ret = max(ret, largestRectangleArea(vtmp));
}
return ret;
}
}; int main()
{
vector<vector<char>> v; char a1[] = { '', '', '', '', ''};
char a2[] = { '', '', '', '', '' };//要用'1'和'0'来赋值!因为是char数组!不能用1,0 !
char a3[] = { '', '', '', '','' };
v.push_back(vector<char>(a1, a1 + ));
v.push_back(vector<char>(a2, a2 + ));
v.push_back(vector<char>(a3, a3 + ));
Solution s;
cout << s.maximalRectangle(v) << endl;
return ;
}

LeetCode-Maximal Rectangle[code]的更多相关文章

  1. leetcode Maximal Rectangle 单调栈

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

  2. LeetCode: Maximal Rectangle 解题报告

    Maximal RectangleGiven a 2D binary matrix filled with 0's and 1's, find the largest rectangle contai ...

  3. [LeetCode] Maximal Rectangle 最大矩形

    Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and ...

  4. [leetcode]Maximal Rectangle @ Python

    原题地址:https://oj.leetcode.com/problems/maximal-rectangle/ 题意:Given a 2D binary matrix filled with 0's ...

  5. [LeetCode] Maximal Rectangle

    Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and ...

  6. [LeetCode] Maximal Rectangle(good)

    Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and ...

  7. leetcode -- Maximal Rectangle TODO O(N)

    Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and ...

  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 85. Maximal Rectangle

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

  10. [LeetCode] Largest Rectangle in Histogram O(n) 解法详析, Maximal Rectangle

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

随机推荐

  1. hadoop踩坑:localhost:50070 无法访问 关闭防火墙

    ubuntu 关闭防火墙:ufw disable hadoop3.0以下版本web访问端口50070:3.0及以上web访问端口9870 参考链接:https://blog.csdn.net/qq_3 ...

  2. 关于DES加密之选择更新版

    数据加密算法(Data Encryption Algorithm,DEA)是一种对称加密算法,很可能是使用最广泛的密钥系统,特别是在保护金融数据的安全中,最初开发的DEA是嵌入硬件中的.通常,自动取款 ...

  3. React创建组件的三种方式比较

    推荐文章: https://www.cnblogs.com/wonyun/p/5930333.html 创建组件的方式主要有: 1.function 方式 2.class App extends Re ...

  4. Delphi对Word一些进阶操作

    利用VBA 编程,可以使许多日常的任务自动完成,使用户的工作更有效率. 1.在启动时显示打开对话框 一般情况下启动Word,Word 会认为是创建一个新文档.如果只是想打开一个旧文档进行编辑,在Wor ...

  5. Oracle 维护数据的完整性 一 索引

    简介:索引是用于加速数据存取的数据对象,合理的使用索引可以大大降低i/o 次数,从而提高数据的访问性能. 当我们从一张表中检索我们需要的数据是,oralce往往会进行全表扫描,就是遍历所有的数据行,来 ...

  6. MVC目录规范

    入口程序 单一入口机制,单一入口指在一个web应用程序中,所有的请求都是指向一个脚本文件,例如我们经常看到某一个网站所有的页面都是index.php??xxxx这样的形式.所有对使用程序的访问都是必须 ...

  7. unity2018使用tileMap生成地图 类似泰拉瑞亚创建和销毁地图块

    参考网站:https://blog.csdn.net/pz789as/article/details/79540890 using System.Collections; using System.C ...

  8. 九度oj 1437 To Fill or Not to Fill 2012年浙江大学计算机及软件工程研究生机试真题

    题目1437:To Fill or Not to Fill 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:1488 解决:345 题目描述: With highways availabl ...

  9. FocusBI: 总线矩阵(原创)

    关注微信公众号:FocusBI 查看更多文章:加QQ群:808774277 获取学习资料和一起探讨问题. <商业智能教程>pdf下载地址 链接:https://pan.baidu.com/ ...

  10. 破解b站极验验证码

    这就是极验验证码,通过拖动滑块移动拼图来验证.我们观察到点击滑块时拼图才会出现,所以我们可以在点击滑块之前截取图像,点击滑块再截取一次图像,将前后两次图像做比较就可以找到图片改动的位置.获得位置后,我 ...