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. easygui.py的安装和下载地址

    easygui下载地址:http://nchc.dl.sourceforge.net/project/easygui/0.97/easygui-0.97.zip 安装:解压后将easygui.py拷贝 ...

  2. oracle--错误笔记(一)

    一,环境模拟 SQL> select status from v$instance; STATUS ------------ OPEN SQL> select * from v$backu ...

  3. [原]SuperMap GIS(JavaScript) 拉框放大和缩小功能实现

    版权声明:本文为博主原创文章,未经博主允许不得转载. var ZoomControl; /* * 拉框缩小 */ function ZoomOut(){ if(ZoomControl==null||Z ...

  4. Vi/Vim命令壁纸图

    下载地址 http://pan.baidu.com/s/1mtQdY

  5. 【Lua】关于遍历指定路径下所有目录及文件

    关于Lua中如何遍历指定文件路径下的所有文件,需要用到Lua的lfs库. 首先创建一个temp.lua文件,用编辑器打开: 要使用lfs库,首先需要把lfs库加载进来 require("lf ...

  6. 【随笔】设置title标题图标为自定义图片

    第一步: 利用图标工具(有很多)制作图标文件(favicon.ico)上传到网站所在的服务器的根目录下,这个文件必须是16*16大小的图标文件. 第二步: 在<head></head ...

  7. lua三目运算符

    lua的类似三目运算符用法 一般化的Lua三目运算为:(a and {b} or {c})[1] local v = (a and {b} or {c})[1]如果a为true,则 v = b 如果a ...

  8. Linux修改BASH命令提示符

    Shell命令提示符及颜色是由PS1来配置: 1.其中PS1常用的参数含义如下: \d :#代表日期,格式为weekday month date,例如:"Mon Aug 1" \H ...

  9. Ajax嵌套Ajax的模版

    引入 在开发中,难免会碰到需要发送两次ajax请求或者更多的情况 情境:我们需要resultB数据,后台提供的接口要先传入参数paramA,获取到resultA,然后resultA作为参数,调用另外一 ...

  10. Codeforces 639B——Bear and Forgotten Tree 3——————【构造、树】

    Bear and Forgotten Tree 3 time limit per test 2 seconds memory limit per test 256 megabytes input st ...