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. springboot 接口返回数据时 net.sf.json.JSONNull["empty"]) 异常

    @ResetController返回数据时出现异常 Could not write JSON: Object is null; nested exception is com.fasterxml.ja ...

  2. 04-oracle时间函数

    add_months(sysdate,x)x月之后的日期:last_day(sysdate)指定日期所在月份的最后一天:next_day(sysdate,'星期x')当前日期后的下一个星期x: mon ...

  3. mojing SDK根据坐标进行移动

    using UnityEngine; using UnityEngine.UI; using System.Collections; public class transforms : MonoBeh ...

  4. Jmeter创建web测试计划

    创建web测试计划 在这一章,我们将学习如何创建基本的测试计划来测试一个web网站.您将创建五个用户并发送请求到JMeter网站的两个页面.同时,设置用户运行测试两次.因此,请求的总数是(5个用户)x ...

  5. Git学习系列之 Git 、CVS、SVN的比较

    Git .CVS.SVN比较 项目源代码的版本管理工具中,比较常用的主要有:CVS.SVN.Git 和 Mercurial  (其中,关于SVN,请参见我的博客:SVN学习系列) 目前Google C ...

  6. 转 关于shell中if 语法结构的广泛误解

    转自 ttp://blog.csdn.net/security134/article/details/6742156 最近学习SHELL编程 这篇文章很好很重要.有些东西不能想当然.同时不是表面看起来 ...

  7. Python基础(3) - 数据类型:4元组类型

    Python Tuple 是不可变 list. 一旦创建了一个 tuple 就不能以任何方式改变它.Tuple是用()包括起来的. Tuple与List都是按照定义的顺序进行排序的,索引从0开始,与 ...

  8. Appium移动端自动化测试-安卓真机+模拟器启动

    一.环境准备 appium-pythin-client版本(0.17),selenium版本(2.53.6)(版本需对应,否则执行脚本可能出错,我用的是这两个版本) macOs版本10.14.1(ap ...

  9. 虚拟机centos笔记整理,持续更新~~

    远程拷贝文件:scp -r 文件名 主机名:完整路径名(冒号不能少)拷贝当前windows系统的文件到当前目录:rz -y 查找文件:updatedb 修改数据库locate 文件名 即可查找文件

  10. 数据结构(二) --- 伸展树(Splay Tree)

    文章图片和代码来自邓俊辉老师课件 概述 伸展树(Splay Tree),也叫分裂树,是一种二叉排序树,它能在O(log n)内完成插入.查找和删除操作.它由丹尼尔·斯立特Daniel Sleator ...