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. Android Notification 的四种使用方式

    实现通知步骤 一般实现通知需要如下步骤: 1.获取 NotificationManager 实例管理通知: 2.实例 Notification 对象: 3.管理事件 Intent: 4.发送通知. 注 ...

  2. 转载:怎样用通俗的语言解释REST,以及RESTful?

    作者:覃超链接:https://www.zhihu.com/question/28557115/answer/48094438来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出 ...

  3. 《C++ Primer》〓〓〓〓〓〓〓〓〓〓【第七章】

    7.5.1 构造函数初始化列表 如果成员是const.引用,或者属于某种未提供默认构造函数的类类型,我们必须通过构造函数初始值列表为这些成员提供初值. 成员的初始化顺序与他们在类定义中的出现顺序一致. ...

  4. jqgrid 各种方法参数的使用

    现在jqGrid对象 tableObj 一.获取选中的行 selected = tableObj.jqGrid('getGridParam', 'selrow'); if (selected == n ...

  5. 阿里云服务器docker搞定镜像

    docker的安装可以看前面的文章 这里我的docker已经安装完成了,该搞镜像了:这里的镜像用的是我以前自己搞的,虽然镜像有点大,但是胜在自己搞的,熟悉(熟悉不熟悉鬼知道) 我的镜像放在了阿里云容器 ...

  6. 微信小程序开发框架整理

    目前除了原生的微信小程序开发外,各大厂商陆续造了自己的开发框架,现整理如下: WePY 腾讯官方开源的小程序组件化开发框架,目前有15K+Star ,一直在更新着,社区活跃,掉坑能快速的找到方法爬出来 ...

  7. Java实现内存分配算法 FF(首次适应算法) BF(最佳适应算法)

    一.概述 因为这次os作业对用户在控制台的输入输出有要求,所以我花了挺多的代码来完善控制台的显示. MemoryAlgorithm类里只是和控制台输入输出有关的操作,而对内存的所有逻辑操作都是用Mem ...

  8. 模拟Springboot一:(零xml配置搭建SSM项目)

    在spring官网文档中无论是spring的基础文档,还是spring-mvc文档都推荐我们使用javaconfig的方式来搭建项目 间接说明 (优点:javaconfig配置>xml配置) 其 ...

  9. [Java反射基础二]获取类的信息

    本文接上文“Class类的使用”,以编写一个用来获取类的信息(成员函数.成员变量.构造函数)的工具类来讲解"反射之获取类的信息" 1.获取成员函数信息 /** * 获取成员函数信息 ...

  10. java多线程之ReentrantLock

    前言 相信学过java的人都知道 synchronized 这个关键词,也知道它用于控制多线程对并发资源的安全访问,兴许,你还用过Lock相关的功能,但你可能从来没有想过java中的锁底层的机制是怎么 ...