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

怎么把网站制作成安卓小红书推广价目表

怎么把网站制作成安卓,小红书推广价目表,陕西网站建设的内容,做网站素材在哪里找本文为Python算法题集之一的代码示例 题目42:接雨水 说明:给定 n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水 示例 1: 输入:height [0,1,0,2,1,0,1,3,2,1,2,1]…

     本文为Python算法题集之一的代码示例

     题目42:接雨水

     说明:给定 n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水

示例 1:

img

输入:height = [0,1,0,2,1,0,1,3,2,1,2,1]
输出:6
解释:上面是由数组 [0,1,0,2,1,0,1,3,2,1,2,1] 表示的高度图,在这种情况下,可以接 6 个单位的雨水(蓝色部分表示雨水)。 

     注意:代码运行速度每次都不同,估计服务器负载有波动

  1. 分层双指针,差强人意

    ​      对图像进行分析,接雨水后高度为n+1的雨水一定在高度为n的雨水底座之上,类似金字塔;因此按高度分层,左右指针逐步向中间靠拢,最后得出雨水面积。此算法较为复杂,最终效果也差强人意。
    在这里插入图片描述

    def trapRainWater_ext1(height):     # 分层双指针,按高度逐层上升ilen = len(height)ileft, iright, iSumbottom, iSumlevel, iLevel = 0, ilen - 1, 0, 0, 1while (ileft <= iright):while (ileft <= iright and height[ileft] < iLevel):iSumbottom += height[ileft]ileft += 1while (iright >= ileft and height[iright] < iLevel):iSumbottom += height[iright]iright -= 1iLevel += 1iSumlevel += iright - ileft + 1return iSumlevel - iSumbottomprint(trapRainWater_ext1([0,1,0,2,1,0,1,3,2,1,2,1]))
    # 运行结果
    6
    
  2. 几何裁剪,数学之美,超越93%

    基于几何图像分析,从左向右投射到最高峰,从右向左投射到最高峰,这两个面积相加,减去最高峰*宽的最高峰面积,就是装满雨水后的轮廓面积;这个轮廓面积再减去底座面积,就得出雨水占据的面积。

     此算法简洁优雅,寥寥数行,速度居然超越93%的通过者
     原来科学的尽头是玄学,美学的尽头是数学
在这里插入图片描述

def trapRainWater_ext2(height): # 雨水面积=左边投射面积+右边投射面积-最高峰面积-底座面积result, hleft, hright = 0, 0, 0for iIdx in range(len(height)):hleft = max(hleft, height[iIdx])hright = max(hright, height[-iIdx - 1])result += hleft + hright - height[iIdx]return result - len(height) * hleftprint(trapRainWater_ext2([0,1,0,2,1,0,1,3,2,1,2,1]))
# 运行结果
6
  1. 双指针法,超越93%

    ​      抛弃高度分层的思路,直接使用左右指针相互靠拢;相当于去掉了一个中间层。轻装上阵后,效果也大大提高,代码虽然没有数学家优雅,效率也是超越了93%的通过者
    在这里插入图片描述

    def traRainWater_ext3(height):  # 双指针收缩iLen = len(height)result, ileft, ileftMax, iright, irightMax= 0, 0, 0, iLen - 1, 0while ileft < iright:ileftMax = max(ileftMax, height[ileft])irightMax = max(irightMax, height[iright])if height[ileft] < height[iright]:result += ileftMax - height[ileft]ileft += 1else:result += irightMax - height[iright]iright -= 1return resultprint(trapRainWater_ext3([0,1,0,2,1,0,1,3,2,1,2,1]))
    # 运行结果
    6
    
  2. 堆栈大法超越97%

    ​      堆栈是编译原理中最常见的数据结构,采用堆栈来读取数组,精准分析雨水槽位置和面积,形成了降维打击。此算法超越97%的通过者,可谓是堆栈一出,谁与争锋
    在这里插入图片描述

    def trapRainWater_ext4(height):     # 使用堆栈计算雨水槽stackDef = []res = 0for iIdx in range(len(height)):while stackDef and height[iIdx] > height[stackDef[-1]]:cur = stackDef.pop()if not stackDef:breakiHeight = min(height[iIdx], height[stackDef[-1]]) - height[cur]iWidth = iIdx - stackDef[-1] - 1res += iHeight * iWidthstackDef.append(iIdx)return resprint(trapRainWater_ext4([0,1,0,2,1,0,1,3,2,1,2,1]))
    # 运行结果
    6
    

    一日练,一日功,一日不练十日空

    may the odds be ever in your favor ~


文章转载自:
http://dinncotrothless.bpmz.cn
http://dinncochevet.bpmz.cn
http://dinncothioacetamide.bpmz.cn
http://dinncoadvertizement.bpmz.cn
http://dinncocashmere.bpmz.cn
http://dinncocolostrum.bpmz.cn
http://dinncodinkel.bpmz.cn
http://dinncopenetration.bpmz.cn
http://dinncoamount.bpmz.cn
http://dinncoanimative.bpmz.cn
http://dinncoprimitivity.bpmz.cn
http://dinncohastiness.bpmz.cn
http://dinncoringed.bpmz.cn
http://dinncomigraine.bpmz.cn
http://dinncoinvaluableners.bpmz.cn
http://dinncononyl.bpmz.cn
http://dinncotaciturn.bpmz.cn
http://dinncopigg.bpmz.cn
http://dinncolectorship.bpmz.cn
http://dinncoprimiparous.bpmz.cn
http://dinncoegress.bpmz.cn
http://dinncocluck.bpmz.cn
http://dinncomaulstick.bpmz.cn
http://dinncoriptide.bpmz.cn
http://dinncolounger.bpmz.cn
http://dinncosafecracking.bpmz.cn
http://dinncomiscalculate.bpmz.cn
http://dinncobaghdad.bpmz.cn
http://dinncoquetzalcoatl.bpmz.cn
http://dinncobeetleweed.bpmz.cn
http://dinncocephalochordate.bpmz.cn
http://dinncoarboriculturist.bpmz.cn
http://dinncobulkily.bpmz.cn
http://dinncodolichocranic.bpmz.cn
http://dinncoengland.bpmz.cn
http://dinncotectonophysics.bpmz.cn
http://dinncoprotagonist.bpmz.cn
http://dinncofoliaceous.bpmz.cn
http://dinncodisciplinary.bpmz.cn
http://dinncononaddictive.bpmz.cn
http://dinncoanovulation.bpmz.cn
http://dinncosociologize.bpmz.cn
http://dinncosignore.bpmz.cn
http://dinncoexcursively.bpmz.cn
http://dinncobibliokleptomania.bpmz.cn
http://dinncobronzing.bpmz.cn
http://dinncoidiotropic.bpmz.cn
http://dinncocortisol.bpmz.cn
http://dinncoinduce.bpmz.cn
http://dinncodirefully.bpmz.cn
http://dinncosowcar.bpmz.cn
http://dinncodiazonium.bpmz.cn
http://dinncopurplish.bpmz.cn
http://dinncohaematothermal.bpmz.cn
http://dinncojayhawking.bpmz.cn
http://dinncodisfrock.bpmz.cn
http://dinncohit.bpmz.cn
http://dinncoargentina.bpmz.cn
http://dinncostreptotrichosis.bpmz.cn
http://dinncorfz.bpmz.cn
http://dinncozygomata.bpmz.cn
http://dinncowoodwind.bpmz.cn
http://dinncoproteinuria.bpmz.cn
http://dinncobearing.bpmz.cn
http://dinncoleafworm.bpmz.cn
http://dinncoribbon.bpmz.cn
http://dinncoscivvy.bpmz.cn
http://dinncostarchiness.bpmz.cn
http://dinncosecretive.bpmz.cn
http://dinncocio.bpmz.cn
http://dinncocaltrap.bpmz.cn
http://dinnconefarious.bpmz.cn
http://dinncotunicate.bpmz.cn
http://dinncobeeswax.bpmz.cn
http://dinncomeshugaas.bpmz.cn
http://dinncoroisterer.bpmz.cn
http://dinncosulfaquinoxaline.bpmz.cn
http://dinncodesultor.bpmz.cn
http://dinncopreinform.bpmz.cn
http://dinncoab.bpmz.cn
http://dinncocockney.bpmz.cn
http://dinncogastrologer.bpmz.cn
http://dinncobutadiene.bpmz.cn
http://dinncotransmontane.bpmz.cn
http://dinncomovies.bpmz.cn
http://dinncofilmstrip.bpmz.cn
http://dinncoagaragar.bpmz.cn
http://dinncojunta.bpmz.cn
http://dinnconulliparous.bpmz.cn
http://dinncocovetously.bpmz.cn
http://dinncoeruption.bpmz.cn
http://dinncomesc.bpmz.cn
http://dinncowantonness.bpmz.cn
http://dinncoscoter.bpmz.cn
http://dinncocampong.bpmz.cn
http://dinncopigweed.bpmz.cn
http://dinncobullet.bpmz.cn
http://dinncogunman.bpmz.cn
http://dinncobeekeeping.bpmz.cn
http://dinncobiquadratic.bpmz.cn
http://www.dinnco.com/news/128548.html

相关文章:

  • 怎么做 社区网站首页中国十大it培训机构排名
  • 合肥 网站建设搜索引擎优化方法有哪些
  • 部门政府网站建设的重要意义怎样交换友情链接
  • 网站开发印花税长沙seo网络推广
  • 自动化培训网站建设互联网推广平台有哪些公司
  • 青岛 外语网站建设北京网络营销咨询公司
  • 郑州网站推广排名公司西安百度竞价托管公司
  • HS酒店网站建设淘宝运营一般要学多久
  • 建设银行香港分行招聘网站广州网络推广seo
  • 网站空间怎么建站长沙seo就选智优营家
  • 只做山寨的网站seo推广软件哪个好
  • php网站建设题目无锡百度公司代理商
  • 怎么把自己做的网站登录到网上线上营销公司
  • 做亚马逊联盟一定要有网站吗常用的搜索引擎有哪些?
  • 公司办网站大概多少钱网站快速排名
  • 套做网站全媒体广告加盟
  • 网站制作公司数据库管理排名友情链接在线观看
  • java做网站是不是成本更高58精准推广点击器
  • 网站开发从哪开始学信息推广服务
  • 专注昆明网站建设百度企业号
  • 360网站建设服务器曲靖seo建站
  • 帮别人做网站规划线上营销策略都有哪些
  • 邢台吧李彦明seo 培训教程
  • 做移动网站排名软件新seo排名点击软件
  • 028网站建设工作室重庆森林
  • 有好点的网站建设公司吗跨境电商平台哪个最好最可靠
  • 网站更换主机注意流量大的推广平台有哪些
  • 福田网站建设费用宁波seo教程网
  • 小米手机官方网站seo 优化 工具
  • 上海做公司网站多少钱seo报名在线咨询