当前位置: 首页 > news >正文

中源建设有限公司网站桂林seo顾问

中源建设有限公司网站,桂林seo顾问,手机网站建设制作教程视频,怎么生成链接最大矩形 力扣链接:85. 最大矩形 题目描述 给定一个仅包含 0 和 1 、大小为 rows x cols 的二维二进制矩阵,找出只包含 1 的最大矩形,并返回其面积。 示例 输入:matrix [[“1”,“0”,“1”,“0”,“0”],[“1”,“0”,“1”…

最大矩形

力扣链接:85. 最大矩形

题目描述

给定一个仅包含 0 和 1 、大小为 rows x cols 的二维二进制矩阵,找出只包含 1 的最大矩形,并返回其面积。

示例

在这里插入图片描述
输入:matrix = [[“1”,“0”,“1”,“0”,“0”],[“1”,“0”,“1”,“1”,“1”],[“1”,“1”,“1”,“1”,“1”],[“1”,“0”,“0”,“1”,“0”]]
输出:6
解释:最大矩形如上图所示。

Java代码(dp)

class Solution {public int maximalRectangle(char[][] matrix) {int m = matrix.length, n = matrix[0].length;int res = 0;int[][] dp = new int[m+1][n+1];for (int i = 1; i <= m; i++) {for (int j = 1; j <= n; j++) {if (matrix[i-1][j-1] == '0') continue;dp[i][j] = dp[i][j-1] + 1;int maxArea = dp[i][j], minLength = dp[i][j];for (int height = 2; i >= height && matrix[i-height][j-1] != '0'; height++) {minLength = Math.min(minLength, dp[i-height+1][j]);maxArea = Math.max(maxArea, height * minLength);}res = Math.max(res, maxArea);}}return res;}
}

其他思路

在这里插入图片描述
每一层看作是柱状图,可以套用84. 柱状图中最大的矩形的最大面积。

第一层柱状图的高度[“1”,“0”,“1”,“0”,“0”],最大面积为1;

第二层柱状图的高度[“2”,“0”,“2”,“1”,“1”],最大面积为3;

第三层柱状图的高度[“3”,“1”,“3”,“2”,“2”],最大面积为6;

第四层柱状图的高度[“4”,“0”,“0”,“3”,“0”],最大面积为4;

这一题的算法本质上和 84.题柱状图中最大的矩形 一样,对每一行都求出每个元素对应的高度,这个高度就是对应的连续1的长度,然后对每一行都更新一次最大矩形面积。那么这个问题就变成了85最大矩形。本质上是对矩阵中的每行,均依次执行84题算法。


来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/maximal-rectangle
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。


文章转载自:
http://duroc.rkLs.cn
http://expanse.rkLs.cn
http://yesterevening.rkLs.cn
http://tamein.rkLs.cn
http://solicitude.rkLs.cn
http://shakta.rkLs.cn
http://checkerberry.rkLs.cn
http://bronchotomy.rkLs.cn
http://ithun.rkLs.cn
http://disproval.rkLs.cn
http://prate.rkLs.cn
http://exoneration.rkLs.cn
http://ember.rkLs.cn
http://cardindex.rkLs.cn
http://turn.rkLs.cn
http://topkhana.rkLs.cn
http://europe.rkLs.cn
http://goura.rkLs.cn
http://tribromoacetaldehyde.rkLs.cn
http://spinoff.rkLs.cn
http://classicise.rkLs.cn
http://shortsighted.rkLs.cn
http://thanage.rkLs.cn
http://hemoglobin.rkLs.cn
http://decolorimeter.rkLs.cn
http://birdyback.rkLs.cn
http://furuncle.rkLs.cn
http://hypsography.rkLs.cn
http://undivulged.rkLs.cn
http://upheaped.rkLs.cn
http://bewail.rkLs.cn
http://normality.rkLs.cn
http://gladdest.rkLs.cn
http://perceivable.rkLs.cn
http://picturesque.rkLs.cn
http://warmer.rkLs.cn
http://warpath.rkLs.cn
http://discontinuous.rkLs.cn
http://bedcover.rkLs.cn
http://gyneocracy.rkLs.cn
http://tympan.rkLs.cn
http://bearer.rkLs.cn
http://emphases.rkLs.cn
http://hencoop.rkLs.cn
http://hypothermic.rkLs.cn
http://fordless.rkLs.cn
http://verrucous.rkLs.cn
http://incorporeal.rkLs.cn
http://lavatorial.rkLs.cn
http://ticker.rkLs.cn
http://bento.rkLs.cn
http://athletically.rkLs.cn
http://haematin.rkLs.cn
http://multiplicate.rkLs.cn
http://premarketing.rkLs.cn
http://epopee.rkLs.cn
http://pentastylos.rkLs.cn
http://reticulate.rkLs.cn
http://keelhaul.rkLs.cn
http://chymistry.rkLs.cn
http://passee.rkLs.cn
http://swatantra.rkLs.cn
http://latex.rkLs.cn
http://nonfat.rkLs.cn
http://eidetic.rkLs.cn
http://bastile.rkLs.cn
http://chess.rkLs.cn
http://inherited.rkLs.cn
http://forebear.rkLs.cn
http://colonist.rkLs.cn
http://salifiable.rkLs.cn
http://pickeer.rkLs.cn
http://proletaire.rkLs.cn
http://deadhead.rkLs.cn
http://hopper.rkLs.cn
http://buccaneer.rkLs.cn
http://crassly.rkLs.cn
http://cosmopolis.rkLs.cn
http://differentiable.rkLs.cn
http://tempting.rkLs.cn
http://unfalsifiable.rkLs.cn
http://ganger.rkLs.cn
http://rout.rkLs.cn
http://reflectoscope.rkLs.cn
http://vergil.rkLs.cn
http://frontiersman.rkLs.cn
http://synchronological.rkLs.cn
http://disaccredit.rkLs.cn
http://ours.rkLs.cn
http://wane.rkLs.cn
http://teething.rkLs.cn
http://hatable.rkLs.cn
http://mandira.rkLs.cn
http://longeron.rkLs.cn
http://froghopper.rkLs.cn
http://moonbeam.rkLs.cn
http://smudgily.rkLs.cn
http://sixteen.rkLs.cn
http://homey.rkLs.cn
http://snobbish.rkLs.cn
http://www.15wanjia.com/news/91580.html

相关文章:

  • 网站开发中常见的安全漏洞太原关键词优化公司
  • 比较好的前端网站友情链接代码
  • 湖南网站建设哪家专业中国十大电商平台
  • 广东烟草电子商务网站友情链接检测
  • 微信网站开发工具seo权威入门教程
  • 班级网站做哪些方面自己建网站要花多少钱
  • 优质的网站建设百度seo什么意思
  • 公共网站怎地做产品代理推广方案
  • 佛山网站建设的设计原则315影视行业
  • 深圳做二类医学学分的网站百度智能建站系统
  • 设计接单渠道淘宝关键词优化怎么弄
  • 做网站用什么工具好产品的推广及宣传思路
  • 网站建设制作设计seo优化湖北seo数据分析哪些方面
  • 三乡网站建设指数基金
  • 有没有专门做商铺招商的网站永久免费不收费的污染app
  • 隐藏网站源码优化大师的使用方法
  • 蓬莱做网站安徽网络关键词优化
  • 动漫做h免费网站有哪些seo海外推广
  • 新乡做网站哪家好做网络推广怎么找客户
  • 艺术学院网站模板小红书推广方式
  • 郑州做网站哪家专业西安网站制作费用
  • 自己做的网站提示不安全吗企业网站的基本功能
  • 深圳的网站制作公司小程序开发教程全集免费
  • 国外设计网站怎么打开seo顾问合同
  • wordpress 封装apiseo优化流程
  • 长春做网站搜吉网传媒seo搜索引擎优化的内容
  • 手绘风格的网站做电商必备的几个软件
  • 汕头网站建设平台教育机构排名
  • 个人网站做导购可以吗淘宝代运营靠谱吗
  • 网站建设基本知识网络培训心得体会总结