85. Maximal Rectangle最大矩形
艾恩凝
个人博客 https://aeneag.xyz/
公众号 技术乱舞
每日一练,保持手感
2021/10/17
题目
https://leetcode-cn.com/problems/maximal-rectangle/
题目分析
本题基于84题解决,这就很简单了,由上到下,首先第一行,其次前两行每列相加,如果有0 就全部为0
题解
class Solution {
public:int largestRectangleArea(vector<int>& heights) {int res = 0 ,len = heights.size();stack<int> my_stack;vector<int> new_heights(len+2,0);for(int i = 1 ; i < len + 1 ; ++i)new_heights[i] = heights[i-1];for(int i = 0 ; i < len+2 ; ++i){while(!my_stack.empty() && new_heights[i] < new_heights[my_stack.top()]){int cur = my_stack.top();my_stack.pop();int cur_height = new_heights[cur];int left = my_stack.top();int right = i;int width = right - left - 1;res = max(res,cur_height*width);}my_stack.push(i);} return res; }int maximalRectangle(vector<vector<char>>& matrix) {if(matrix.size() == 0)return 0;int row = matrix.size(),col = matrix[0].size();vector<int> tmp(col,0);//for(int i = 0 ; i < col ; ++i)tmp[i] = atoi(matrix[0][i]);//此处char 转int 不知道为什么这个函数说没有,换了写法int res = largestRectangleArea(tmp);for(int i = 0 ; i < row ; ++i){for(int j = 0 ; j < col ; ++j){//tmp[j] += atoi(matrix[i][j]);if(matrix[i][j] == '1'){++tmp[j];}else{tmp[j] = 0;}}res = max(res,largestRectangleArea(tmp));}return res;}
};
欢迎关注 #公众号:技术乱舞 一起交流
灵魂碰撞
85. Maximal Rectangle最大矩形相关推荐
- 【DP】LeetCode 85. Maximal Rectangle
LeetCode 85. Maximal Rectangle Solution1: 一语惊醒梦中人啊,参考链接:https://www.youtube.com/watch?v=2Yk3Avrzauk ...
- leetcode 85. Maximal Rectangle | 85. 最大矩形(单调栈)
题目 https://leetcode.com/problems/maximal-rectangle/ 题解 本题与 leetcode 84. Largest Rectangle in Histogr ...
- 85. Maximal Rectangle 由1拼出的最大矩形
[抄题]: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1 ...
- 【leetcode】85. Maximal Rectangle 0/1矩阵的最大全1子矩阵
1. 题目 Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1 ...
- [leetcode]@python 85. Maximal Rectangle
题目链接 https://leetcode.com/problems/maximal-rectangle/ 题目原文 Given a 2D binary matrix filled with 0's ...
- 85. Maximal Rectangle
用dp计算矩形面积 文章目录 1题目理解 2分析 2.1 暴力搜索 2.2 动态规划 3 相关题目 1题目理解 输入:char[][] matrix 是一个二维数组,值由0和1组成. 输出:一个矩形的 ...
- LeetCode 85. Maximal Rectangle --python,java解法
题目地址: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1 ...
- 085 Maximal Rectangle 最大矩形
给定一个填充了 0 和 1 的二进制矩阵,找到最大的只包含 1 的矩形并返回其面积. 例如,给出以下矩阵: 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0 返回 6 详 ...
- [LeetCode]Maximal Rectangle
Maximal Rectangle Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle conta ...
最新文章
- 对F-score的理解
- 对于白神贪心问题的感悟
- SQLServer导入excel报错因缺少插件
- java作业不能运行_从Windows运行时,YARN作业失败
- 13日直播预告丨Oracle多套库整合到多租户平台案例分享
- 关于rabbitmq的介绍
- 深度学习网络训练中出现nan的原因分析
- 用ClusterSSH管理多台Linux服务器(2)
- SRM 403(1-250pt, 1-500pt)
- Coinbase、BlockFi相继开启上市准备工作,但SEC准备好了吗?
- Play框架文件上传
- PostgreSQL 9.6源码解析之XLOG生成
- 微软数据中心将到南非!AWS也将要跟进
- SSM(spring.struts2.mybatis)注解式开发步骤
- 三台机器互相免密登录
- acmore|acmore.cc1211采油区域1212会议中心1213抢掠计划APIO2009
- Java反序列化(一) - Java反射机制
- Anders Hejlsberg 访谈 .-转载
- Linux终端设备解析
- (一)python网络爬虫(理论+实战)——爬虫的初步认识
热门文章
- 人脸识别-----Olivetti Faces人脸数据集合处理
- 简单的射击类Android游戏--《环形射击》
- C++11特性及其它常用特性
- java:熊怪吃核桃
- 荆楚计算机专业分数线理工,荆楚理工学院分数线
- 名帖194 米芾 行书《珊瑚帖》
- 本站最全-unity常用API大全(万字详解),不信你不收藏
- 美团四面 Java 岗,终获 offer,我是这么回答面试官的
- Java计算机毕业设计图书馆座位预约管理系统源码+系统+数据库+lw文档
- 形容词,名词记忆(三):ment, ent后缀常用词