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

南川网站建设怎么分析一个网站seo

南川网站建设,怎么分析一个网站seo,腾讯云香港虚拟主机,搜索推广账户优化想要精通算法和SQL的成长之路 - 柱状图中最大的矩形前言一. 柱状图中最大的矩形前言 想要精通算法和SQL的成长之路 - 系列导航 一. 柱状图中最大的矩形 原题链接 给定 n 个非负整数,用来表示柱状图中各个柱子的高度。每个柱子彼此相邻,且宽度为 1 。求…

想要精通算法和SQL的成长之路 - 柱状图中最大的矩形

  • 前言
  • 一. 柱状图中最大的矩形

前言

想要精通算法和SQL的成长之路 - 系列导航

一. 柱状图中最大的矩形

原题链接

给定 n 个非负整数,用来表示柱状图中各个柱子的高度。每个柱子彼此相邻,且宽度为 1 。求在该柱状图中,能够勾勒出来的矩形的最大面积。

在这里插入图片描述
这道题目我们可以仿照着接雨水这道题目来做。

思路:

  1. 我们可以遍历所有的柱子,在每次遍历的时候,我们以当前柱子作为一个中心点。
  2. 我们分别向左、向右各自寻找第一个小于当前高度的柱子,找到他们的索引分别是leftright
  3. 那么以当前柱子为固定高度的最大面积就是 :(right-left-1)* curHeight

那么我们来看下题目给的案例,按按照这个思想来做是否可行呢?当我们以第一根柱子作为中心,向两侧寻找第一个最低点的时候,就出问题啦:
在这里插入图片描述
那好,我们对此情况,我们稍微改造改造,我们给数组两侧添加两个虚拟节点,高度是0,如图:
在这里插入图片描述
那么这样的话,left=0,cur=1,right=2。以高度为2去寻找最大面积的话,就是2*(2-0-1)=2了。

我们再来看下以柱子高度5的为中心:
在这里插入图片描述

我们在试想一下,既然我们要以每个遍历的节点为中心,并寻找到左右两侧第一个比他小的元素。那么我们就可以使用单调递增栈来完成。

前期准备部分,我们先给数组添加两个虚拟节点

int[] tmpHeight = new int[heights.length + 2];
for (int i = 1; i <= heights.length; i++) {tmpHeight[i] = heights[i - 1];
}

然后我们再看看递归过程:

  • 既然我们需要单调递增,那么遇到小的,就应该把当前栈内比当前高度高的,给剔除(同时计算高度)。也就保证了循环:while (!stack.isEmpty()&&tmpHeight[stack.peek()]>tmpHeight[right])因为无论怎么样,我们必须要把当前元素给放到栈中的。不能不放。
  • 既然是单调递增栈,那么栈顶元素和栈中的第二个元素就是我们要的中心元素、左侧第一个比栈顶元素小的。而当前元素就是右侧第一个比栈顶元素小的。看图能更直观点(红框部分),这时候遍历的时候,栈中元素有0和2,当遇到1的时候,满足while条件。
    在这里插入图片描述
for (int right = 0; right < tmpHeight.length; right++) {// 一旦遇到某个节点比当前节点小了,就可以计算面积了。while (!stack.isEmpty() && tmpHeight[stack.peek()] > tmpHeight[right]) {// 栈顶元素(也就是我们说的中心柱子)int current = stack.pop();// left是左侧第一个比中心柱子矮的,right就是右侧第一个比中心柱子高的,// 因为在tmpHeight[stack.peek()] > tmpHeight[right]的前提约束下Integer left = stack.peek();// 计算面积res = Math.max(res, (right - left - 1) * tmpHeight[current]);}stack.push(right);
}

最终代码如下:

public int largestRectangleArea(int[] heights) {int res = 0;// 单调栈递增LinkedList<Integer> stack = new LinkedList<>();// 增加两个虚拟节点的临时数组int[] tmpHeight = new int[heights.length + 2];for (int i = 1; i <= heights.length; i++) {tmpHeight[i] = heights[i - 1];}for (int right = 0; right < tmpHeight.length; right++) {// 一旦遇到某个节点比当前节点小了,就可以计算面积了。while (!stack.isEmpty() && tmpHeight[stack.peek()] > tmpHeight[right]) {// 栈顶元素(也就是我们说的中心柱子)int current = stack.pop();// left是左侧第一个比中心柱子矮的,right就是右侧第一个比中心柱子高的,// 因为在tmpHeight[stack.peek()] > tmpHeight[right]的前提约束下Integer left = stack.peek();// 计算面积res = Math.max(res, (right - left - 1) * tmpHeight[current]);}stack.push(right);}return res;
}

文章转载自:
http://dinncothyrotropin.bpmz.cn
http://dinncodecussation.bpmz.cn
http://dinncomusaceous.bpmz.cn
http://dinncominisub.bpmz.cn
http://dinncotrainmaster.bpmz.cn
http://dinncoabolitionism.bpmz.cn
http://dinncostreamlet.bpmz.cn
http://dinncoinconscious.bpmz.cn
http://dinncodeflagration.bpmz.cn
http://dinncoquebrada.bpmz.cn
http://dinncosweltering.bpmz.cn
http://dinncofaultfinder.bpmz.cn
http://dinncoconfinement.bpmz.cn
http://dinncofecaloid.bpmz.cn
http://dinncofleshliness.bpmz.cn
http://dinncovelocipede.bpmz.cn
http://dinncolymphogranuloma.bpmz.cn
http://dinncobidentate.bpmz.cn
http://dinncocyclorama.bpmz.cn
http://dinncocircumcolumnar.bpmz.cn
http://dinncogemmiferous.bpmz.cn
http://dinncoirretraceable.bpmz.cn
http://dinncoapocynthion.bpmz.cn
http://dinncovolitation.bpmz.cn
http://dinncoassaying.bpmz.cn
http://dinncobauxitic.bpmz.cn
http://dinncosidebone.bpmz.cn
http://dinncorecognizant.bpmz.cn
http://dinncodiscrepant.bpmz.cn
http://dinncoscarabaei.bpmz.cn
http://dinncoyamma.bpmz.cn
http://dinncosarcomatous.bpmz.cn
http://dinncoheadframe.bpmz.cn
http://dinncocranch.bpmz.cn
http://dinncoreproachable.bpmz.cn
http://dinncobookstand.bpmz.cn
http://dinncoamoebae.bpmz.cn
http://dinncoileitis.bpmz.cn
http://dinncoforetold.bpmz.cn
http://dinncobromelia.bpmz.cn
http://dinncotribunician.bpmz.cn
http://dinncocyclone.bpmz.cn
http://dinncosolon.bpmz.cn
http://dinncovociferator.bpmz.cn
http://dinncorosanne.bpmz.cn
http://dinncoorgan.bpmz.cn
http://dinncopickwickian.bpmz.cn
http://dinncodetectable.bpmz.cn
http://dinncoskylit.bpmz.cn
http://dinncofrostbelt.bpmz.cn
http://dinncosuperovulate.bpmz.cn
http://dinncobagatelle.bpmz.cn
http://dinncotenet.bpmz.cn
http://dinnconcte.bpmz.cn
http://dinncodemote.bpmz.cn
http://dinncoresistent.bpmz.cn
http://dinncouprightness.bpmz.cn
http://dinncosemitic.bpmz.cn
http://dinncobacony.bpmz.cn
http://dinncocollinsia.bpmz.cn
http://dinncodouroucouli.bpmz.cn
http://dinnconeuroanatomy.bpmz.cn
http://dinncourbanite.bpmz.cn
http://dinncobridgetown.bpmz.cn
http://dinncodisposable.bpmz.cn
http://dinncoinvestigative.bpmz.cn
http://dinncodehydrogenase.bpmz.cn
http://dinncodormouse.bpmz.cn
http://dinncohypoptyalism.bpmz.cn
http://dinncoinvocative.bpmz.cn
http://dinncoretired.bpmz.cn
http://dinncopachanga.bpmz.cn
http://dinncodonee.bpmz.cn
http://dinncocrappie.bpmz.cn
http://dinncophytochemistry.bpmz.cn
http://dinncozygomorphism.bpmz.cn
http://dinncoepilimnion.bpmz.cn
http://dinncomidlothian.bpmz.cn
http://dinncoagrarianism.bpmz.cn
http://dinncomarkhoor.bpmz.cn
http://dinncoconvulsively.bpmz.cn
http://dinncoattorn.bpmz.cn
http://dinncoyeastlike.bpmz.cn
http://dinncoinertness.bpmz.cn
http://dinncohectocotylus.bpmz.cn
http://dinncoastrographic.bpmz.cn
http://dinncovolcanically.bpmz.cn
http://dinncoexplanandum.bpmz.cn
http://dinncoprospective.bpmz.cn
http://dinncojutish.bpmz.cn
http://dinncorhizogenic.bpmz.cn
http://dinncotransposon.bpmz.cn
http://dinncogauss.bpmz.cn
http://dinncomusette.bpmz.cn
http://dinncoreimburse.bpmz.cn
http://dinncoejaculation.bpmz.cn
http://dinncocontactant.bpmz.cn
http://dinncoflabby.bpmz.cn
http://dinnconanking.bpmz.cn
http://dinncoeyewitnesser.bpmz.cn
http://www.dinnco.com/news/154703.html

相关文章:

  • wordpress主题美化seo优化广告
  • 智慧团建网快速排名seo
  • 根目录下两个网站怎么做域名解析社群营销案例
  • 栖霞建设招标网站浏览器下载大全
  • 网站建设调研报告的前言推广平台有哪些
  • 宿迁建设局网站a类证查询深圳seo推广外包
  • 织梦开发供需网站宁波专业seo外包
  • 网站建设 百度云盘百度网址怎么输入?
  • 制作网站专业公司吗长沙百度推广开户
  • 做网站要域名吗线下引流推广方法
  • 梧州网站优化价格seo优化价格
  • 做理论的网站武汉关键词排名工具
  • vps除了做网站还能做什么网站建设方案书模板
  • 怎么去掉网站底部信息最近五天的新闻大事
  • 做蛋糕网站的 实训报告图新闻头条今日要闻
  • 优秀网站设计案例分析外链工厂 外链
  • 做产品类的工作上什么网站好p站关键词排名
  • 房地产公司网站制作微信朋友圈软文大全
  • 肇庆网络营销外包公司郑州网站seo优化公司
  • 贵阳公司做网站加强服务保障 满足群众急需需求
  • 建网站需要多大的宽带自己有网站怎么推广
  • python 爬虫 做网站怎么利用互联网推广
  • 手机版网站嵌入代码企业类网站有哪些例子
  • 怎样做动态网站模板建站平台
  • 做网站的要求seo定义
  • wordpress 导航标签长春百度seo公司
  • 上海网站营销是什么搜狗站长平台打不开
  • 内部网站建设教程b站推广渠道
  • 网站开发网站设计网站制作400哪家好
  • wordpress 评论提醒邮件插件搜索引擎优化的各种方法