LeetCode-Maximal Rectangle[code]
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]的更多相关文章
- leetcode Maximal Rectangle 单调栈
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4052721.html 题目链接:leetcode Maximal Rectangle 单调栈 ...
- LeetCode: Maximal Rectangle 解题报告
Maximal RectangleGiven a 2D binary matrix filled with 0's and 1's, find the largest rectangle contai ...
- [LeetCode] Maximal Rectangle 最大矩形
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and ...
- [leetcode]Maximal Rectangle @ Python
原题地址:https://oj.leetcode.com/problems/maximal-rectangle/ 题意:Given a 2D binary matrix filled with 0's ...
- [LeetCode] Maximal Rectangle
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and ...
- [LeetCode] Maximal Rectangle(good)
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and ...
- 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 ...
- leetcode面试准备: Maximal Rectangle
leetcode面试准备: Maximal Rectangle 1 题目 Given a 2D binary matrix filled with 0's and 1's, find the larg ...
- 求解最大矩形面积 — leetcode 85. Maximal Rectangle
之前切了道求解最大正方形的题,题解猛戳 这里.这道题 Maximal Rectangle 题意与之类似,但是解法完全不一样. 先来看这道题 Largest Rectangle in Histogram ...
- [LeetCode] Largest Rectangle in Histogram O(n) 解法详析, Maximal Rectangle
Largest Rectangle in Histogram Given n non-negative integers representing the histogram's bar height ...
随机推荐
- idea validation code
K71U8DBPNE-eyJsaWNlbnNlSWQiOiJLNzFVOERCUE5FIiwibGljZW5zZWVOYW1lIjoibGFuIHl1IiwiYXNzaWduZWVOYW1lIjoiI ...
- [转] Hive函数大全
1.内置运算符 1.1关系运算符 运算符 类型 说明 A = B 所有原始类型 如果A与B相等,返回TRUE,否则返回FALSE A == B 无 失败,因为无效的语法. SQL使用”=”,不使用”= ...
- JMeter元件的作用域与执行顺序
元件的作用域 先来讨论一下元件有作用域.<JMeter基础元件介绍>一节中,我们介绍了8类可被执行的元件(测试计划与线程组不属于元件),这些元件中,取样器 是典型的不与其它元件发生交互作用 ...
- 【Css】一个简单的选项卡
这次来做一个简单的选项卡. 选项卡其实就分3个部分:html代码,用于显示的内容:css代码,用于显示的样式:javascript代码,用于点击事件. 老规矩,先写一个html坯子. <!DOC ...
- Shiro: 权限管理
一.权限管理 1.什么是权限管理 权限管理属于系统安全的范畴,权限管理实现对用户访问系统的控制,按照安全规则或者安全策略控制用户可以访问且只能访问自己被授权的资源. 权限管理包括用户身份认证和 ...
- 【c++】explicit 隐式类类型转换
上代码 #include <iostream> #include <sstream> using namespace std; class A { public: A(cons ...
- 问题集录06--SpringBoot创建Maven项目
1. 如下图,打开idea之后,file -> new -> project2. 如下图,在弹出的new project 页面,选择maven -> 勾选Create from ar ...
- MVC-cshtml(条件编译已关闭)
加单引号
- RabbitMQ - 介绍
RabbitMQ是个健壮.易用.开源.支持多种操作系统和语言的message broker. 当然,一切的前提是机器里面正在运行着rabbitmq-server. 点击下面的图片下载: rabbitM ...
- 流畅的python和cookbook学习笔记(八)
1.函数的默认参数必须不可变 如果函数的默认参数为可变的对象,那么默认参数在函数外被修改也会影响到函数本身的. >>> def spam(a, b=None): # b要为不可变参数 ...