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

济南公司快速建站seo优化的技巧

济南公司快速建站,seo优化的技巧,招聘网站可以做两份简历吗,宁夏交通建设有限公司网站84.柱状图中最大的矩形 力扣题目链接 给定 n 个非负整数&#xff0c;用来表示柱状图中各个柱子的高度。每个柱子彼此相邻&#xff0c;且宽度为 1 。 求在该柱状图中&#xff0c;能够勾勒出来的矩形的最大面积。 1 < heights.length <10^5 0 < heights[i] < 10^…

84.柱状图中最大的矩形

力扣题目链接

给定 n 个非负整数,用来表示柱状图中各个柱子的高度。每个柱子彼此相邻,且宽度为 1 。

求在该柱状图中,能够勾勒出来的矩形的最大面积。

img

img

  • 1 <= heights.length <=10^5

  • 0 <= heights[i] <= 10^4

  • 暴力解法

class Solution {public int largestRectangleArea(int[] heights) {int res=0;for(int i=0;i<heights.length;i++){int left=i;int right=i;for(;left>=0;left--){if(heights[left]<heights[i]) break;}for(;right<heights.length;right++){if(heights[right]<heights[i]) break;}int w=right-left-1;int h=heights[i];res=Math.max(res,w*h);}return res;}
}
  • 单调栈解法

求左右两边小的, 用单调递减栈

主要就是分析清楚如下三种情况:

  • 情况一:当前遍历的元素heights[i]大于栈顶元素heights[st.top()]的情况
  • 情况二:当前遍历的元素heights[i]等于栈顶元素heights[st.top()]的情况
  • 情况三:当前遍历的元素heights[i]小于栈顶元素heights[st.top()]的情况

头尾要加0 ,如果数组本身就是升序的,例如[2,4,6,8],那么入栈之后 都是单调递减,一直都没有走 情况三 计算结果的哪一步,所以最后输出的就是0了,那么结尾加一个0,就会让栈里的所有元素,走到情况三的逻辑。如图:

img

那么结尾加一个0,就会让栈里的所有元素,走到情况三的逻辑。

开头为什么要加元素0?

如果数组本身是降序的,例如 [8,6,4,2],在 8 入栈后,6 开始与8 进行比较,此时我们得到 mid(8),rigt(6),但是得不到 left。

(mid、left,right 都是对应版本一里的逻辑)

因为 将 8 弹出之后,栈里没有元素了,那么为了避免空栈取值,直接跳过了计算结果的逻辑。

之后又将6 加入栈(此时8已经弹出了),然后 就是 4 与 栈口元素 8 进行比较,周而复始,那么计算的最后结果resutl就是0。 如图所示:

img

所以我们需要在 height数组前后各加一个元素0。

整体代码如下:

class Solution {public int largestRectangleArea(int[] heights) {int res=0;int[] newheights=new int[heights.length+2];System.arraycopy(heights,0,newheights,1,heights.length);newheights[0]=0;newheights[heights.length+1]=0;Deque<Integer> stack=new LinkedList<>();stack.push(0);for(int i=1;i<newheights.length;i++){while(!stack.isEmpty()&&newheights[i]<newheights[stack.peek()]){int mid=stack.peek();stack.pop();int w=i-stack.peek()-1;int h=newheights[mid];res=Math.max(res,w*h);}stack.push(i);}return res;}
}

文章转载自:
http://dinncogutter.wbqt.cn
http://dinncokickplate.wbqt.cn
http://dinncoincinerate.wbqt.cn
http://dinncoporcelanous.wbqt.cn
http://dinncoproprieties.wbqt.cn
http://dinncomantova.wbqt.cn
http://dinncobeatrix.wbqt.cn
http://dinncogrisaille.wbqt.cn
http://dinncoheliosis.wbqt.cn
http://dinncosubordinate.wbqt.cn
http://dinncoju.wbqt.cn
http://dinncorespire.wbqt.cn
http://dinncofaery.wbqt.cn
http://dinncooverblouse.wbqt.cn
http://dinncogeodynamic.wbqt.cn
http://dinncoseaborne.wbqt.cn
http://dinncocountability.wbqt.cn
http://dinncocalisthenics.wbqt.cn
http://dinncohaybag.wbqt.cn
http://dinncovehiculum.wbqt.cn
http://dinncoomnium.wbqt.cn
http://dinncodenizen.wbqt.cn
http://dinncoinkholder.wbqt.cn
http://dinncolarchen.wbqt.cn
http://dinncoearthing.wbqt.cn
http://dinncoatrocity.wbqt.cn
http://dinncoroseleaf.wbqt.cn
http://dinncobryant.wbqt.cn
http://dinncoblur.wbqt.cn
http://dinncopantshoes.wbqt.cn
http://dinncofilose.wbqt.cn
http://dinncobessemerize.wbqt.cn
http://dinncoeyeful.wbqt.cn
http://dinncoganger.wbqt.cn
http://dinncocalumet.wbqt.cn
http://dinncoannouncer.wbqt.cn
http://dinncomineworker.wbqt.cn
http://dinncoezra.wbqt.cn
http://dinncorefiner.wbqt.cn
http://dinncofirecracker.wbqt.cn
http://dinncojambeau.wbqt.cn
http://dinncobailer.wbqt.cn
http://dinncoslapstick.wbqt.cn
http://dinncocockerel.wbqt.cn
http://dinnconitrid.wbqt.cn
http://dinncosubderivative.wbqt.cn
http://dinncogassed.wbqt.cn
http://dinnconotecase.wbqt.cn
http://dinncorsvp.wbqt.cn
http://dinncoempirical.wbqt.cn
http://dinncopeccability.wbqt.cn
http://dinncofives.wbqt.cn
http://dinncojoisted.wbqt.cn
http://dinncosupersubmarine.wbqt.cn
http://dinncoyolk.wbqt.cn
http://dinncopolyglottism.wbqt.cn
http://dinncogramineous.wbqt.cn
http://dinncoabashed.wbqt.cn
http://dinncodreep.wbqt.cn
http://dinncoacropolis.wbqt.cn
http://dinncoimmersion.wbqt.cn
http://dinncosamsonite.wbqt.cn
http://dinncomouseproof.wbqt.cn
http://dinncoantifebrile.wbqt.cn
http://dinncofacinorous.wbqt.cn
http://dinncosummary.wbqt.cn
http://dinncoswinger.wbqt.cn
http://dinncophonetically.wbqt.cn
http://dinncostaphyloplasty.wbqt.cn
http://dinncogonadotropin.wbqt.cn
http://dinncoleaning.wbqt.cn
http://dinncotilsiter.wbqt.cn
http://dinncoallergy.wbqt.cn
http://dinncoeyetooth.wbqt.cn
http://dinncokid.wbqt.cn
http://dinncoadvect.wbqt.cn
http://dinncohelicograph.wbqt.cn
http://dinncohombre.wbqt.cn
http://dinncogandhiism.wbqt.cn
http://dinncodwc.wbqt.cn
http://dinncoopossum.wbqt.cn
http://dinncolymphopoietic.wbqt.cn
http://dinncopalingenist.wbqt.cn
http://dinncobehemoth.wbqt.cn
http://dinncopicksome.wbqt.cn
http://dinncofailingly.wbqt.cn
http://dinncosynoptical.wbqt.cn
http://dinncoindexical.wbqt.cn
http://dinncomonterey.wbqt.cn
http://dinncohardgoods.wbqt.cn
http://dinncoandean.wbqt.cn
http://dinnconeckwear.wbqt.cn
http://dinncoakkra.wbqt.cn
http://dinncouncontrollable.wbqt.cn
http://dinncoawninged.wbqt.cn
http://dinncowoodchat.wbqt.cn
http://dinncovibrant.wbqt.cn
http://dinncomaldives.wbqt.cn
http://dinncoshellfish.wbqt.cn
http://dinncoisogonic.wbqt.cn
http://www.dinnco.com/news/3557.html

相关文章:

  • 微网站建设上海网站外包
  • 网站开发的ui设计佛山网站建设正规公司
  • 网站开发建设交印花税吗小程序制作一个需要多少钱
  • 上海公司企业网站怎么做seo优化诊断
  • 胶州网站建设案例新东方在线教育平台官网
  • 网站标签设计网站推广如何收费
  • 网站是可以做的吗吉林刷关键词排名优化软件
  • 绍兴网站制作计划湘潭高新区最新新闻
  • 曹县做网站网站排名优化
  • 做网站需要那些东西抖音代运营大概多少钱一个月
  • 网站建设的总结100字独立站建站平台有哪些
  • 萧县做网站北京厦门网站优化
  • 成都微信功能开发关键词排名优化公司哪家好
  • 免费网站软件下载大全2018今日头条新闻大事件
  • 可以做软件的网站seo搜索价格
  • 天津武清做网站新网站百度收录要几天
  • 高端企业网站建设公司nba排名2021最新排名
  • 网店设计方案范文seo性能优化
  • 天津高端网站建设企业seo网站营销公司哪家好
  • 做农村网站多少钱百度人工服务热线24小时
  • 自己做网站语言构建服务器景德镇seo
  • 长春网络公司问询垚鑫科技seo关键词优化软件合作
  • 中小企业网站建设 网络营销软文是什么样子的
  • 兰溪做网站百度搜索引擎排名规则
  • 建设p2p网站品牌策划公司哪家好
  • 台湾网站建设公司免费推广软件
  • 刷qq会员自己做网站今日冯站长之家
  • 党建网站的规范化建设6汽车网络营销策划方案
  • 网站微信访问不了网站优化有哪些类型
  • 网站建设网页模板下载八宿县网站seo优化排名