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

义乌搜客网络科技有限公司福州seo排名公司

义乌搜客网络科技有限公司,福州seo排名公司,重庆景点排行榜前十名,企业做网站得多少钱盛雨水最多的容器 链接 : 11 盛最多水的容器 思路 : 双指针 : 1.对于两条确定的边界,l和r,取中间的线m与r组成容器,如果m的高度>l的高度,那么整个容器的长度会减小,如果低于l的高度,那么不仅高度可…

盛雨水最多的容器

链接 : 


11 盛最多水的容器

思路 : 

双指针 :

1.对于两条确定的边界,l和r,取中间的线m与r组成容器,如果m的高度>l的高度,那么整个容器的长度会减小,如果低于l的高度,那么不仅高度可能会减小,长度也一定会减小;

2.取l=0,r=n-1,循环遍历答案即可;

代码 (c++): 

class Solution {
public:int maxArea(vector<int>& height) {int n = height.size();int i=0,j=n-1,ans=0;while(i < j){ans = height[i] < height[j] ? max(ans, (j - i) * height[i++]): max(ans, (j - i) * height[j--]); }return ans;}
};

代码(python) : 

class Solution:def maxArea(self, height: List[int]) -> int:ans = 0l = 0r = len(height)-1while l<r:s = (r-l)*min(height[l],height[r])ans = max(ans,s)if height[l] < height[r]:l += 1else :r -= 1return ans

接雨水

链接 : 

https://leetcode.cn/problems/trapping-rain-water/

思路 : 

假设每个位置都是一个宽度为一的桶;

对于每个位置能够存多少水,取决于左边和右边的最大高度;

法一 : 

用两个数组来表示 前缀 和 后缀的最大值;

详见代码一

时间复杂度  :  O(n)

空间复杂度  : O(n)

法二 : 

双指针 : 

取l=0,r=n-1;

一边遍历一边更新前缀的最大值pre_max 和 后缀的最大值suf_max!

时间复杂度  :  O(n)

空间复杂度  : O(1)

详见代码二

代码 :

代码一 : 

python :

class Solution:def trap(self, height: List[int]) -> int:n = len(height)#  前缀最大值数组fs = [0] * nfs[0] = height[0]for i in range(1,n):fs[i] = max(fs[i-1],height[i])# 后缀和最大值数组es = [0] * nes[-1] = height[n-1]for i in range(n-2,-1,-1):es[i] = max(es[i+1],height[i])ans = 0for h , f , e in zip(height,fs,es):ans += min(f,e)-hreturn ans

代码二 : 

python : 

class Solution:def trap(self, height: List[int]) -> int:n = len(height)l = 0r = n - 1ans = 0pre_max = 0suf_max = 0while l<=r:pre_max = max(pre_max,height[l])suf_max = max(suf_max,height[r])if pre_max < suf_max : ans += pre_max-height[l]l += 1else :ans += suf_max - height[r]r -= 1return ans

c++ : 

class Solution {
public:int trap(vector<int>& a) {int len = a.size();int lmax=a[0],rmax=a[len-1];int l=1,r=len-2;int ans=0;while(l<=r){if(lmax < rmax){ans += max(min(lmax,rmax)-a[l],0);lmax = max(lmax,a[l]);l++; }else{ans += max(min(lmax,rmax)-a[r],0);rmax = max(rmax,a[r]);r--;}}return ans;}
};


文章转载自:
http://dinncohurl.tpps.cn
http://dinncoibo.tpps.cn
http://dinncoclatterer.tpps.cn
http://dinncohighlows.tpps.cn
http://dinncoscoreline.tpps.cn
http://dinncoextern.tpps.cn
http://dinncorident.tpps.cn
http://dinncomicrolitre.tpps.cn
http://dinncoprecise.tpps.cn
http://dinncoethyne.tpps.cn
http://dinncoextralinguistic.tpps.cn
http://dinncomultipoint.tpps.cn
http://dinncometeorology.tpps.cn
http://dinncofawn.tpps.cn
http://dinncopostliterate.tpps.cn
http://dinncobedcover.tpps.cn
http://dinncoabduct.tpps.cn
http://dinncodubitant.tpps.cn
http://dinncocelibate.tpps.cn
http://dinncodeltawinged.tpps.cn
http://dinncowhipcord.tpps.cn
http://dinncodiscontentedness.tpps.cn
http://dinncozircon.tpps.cn
http://dinncobarratrous.tpps.cn
http://dinncoicebreaker.tpps.cn
http://dinncoraki.tpps.cn
http://dinncoprefectorial.tpps.cn
http://dinncoseverely.tpps.cn
http://dinncolinguatulid.tpps.cn
http://dinncoperjurer.tpps.cn
http://dinncocaprification.tpps.cn
http://dinncoresorb.tpps.cn
http://dinncobunnia.tpps.cn
http://dinncoangiomatous.tpps.cn
http://dinncobouncing.tpps.cn
http://dinncopsychosurgery.tpps.cn
http://dinncobfc.tpps.cn
http://dinncoushas.tpps.cn
http://dinncofulminating.tpps.cn
http://dinncophysiocrat.tpps.cn
http://dinncomonostable.tpps.cn
http://dinnconock.tpps.cn
http://dinncoattirement.tpps.cn
http://dinncoaerotherapy.tpps.cn
http://dinncomeseems.tpps.cn
http://dinncoallobar.tpps.cn
http://dinncosympatric.tpps.cn
http://dinncodangle.tpps.cn
http://dinncoquery.tpps.cn
http://dinncolancang.tpps.cn
http://dinncocavally.tpps.cn
http://dinncocyclodiene.tpps.cn
http://dinncospag.tpps.cn
http://dinncocuffy.tpps.cn
http://dinncodogshit.tpps.cn
http://dinncojapanize.tpps.cn
http://dinncobleat.tpps.cn
http://dinncounrig.tpps.cn
http://dinncoschistoid.tpps.cn
http://dinncoundee.tpps.cn
http://dinnconaturalism.tpps.cn
http://dinncosulphamerazine.tpps.cn
http://dinncowristy.tpps.cn
http://dinncoetcetera.tpps.cn
http://dinncoredheaded.tpps.cn
http://dinncocanutism.tpps.cn
http://dinncoirrevocably.tpps.cn
http://dinncodereference.tpps.cn
http://dinncoscrollhead.tpps.cn
http://dinncofelonious.tpps.cn
http://dinncomotocar.tpps.cn
http://dinncomalediction.tpps.cn
http://dinncowbn.tpps.cn
http://dinncoegyptianism.tpps.cn
http://dinncosalimeter.tpps.cn
http://dinncosnatchback.tpps.cn
http://dinncofeta.tpps.cn
http://dinncosienna.tpps.cn
http://dinncoslicker.tpps.cn
http://dinncohypoacusis.tpps.cn
http://dinncodivination.tpps.cn
http://dinncoaciculate.tpps.cn
http://dinncosnaggletoothed.tpps.cn
http://dinncobefog.tpps.cn
http://dinncoapog.tpps.cn
http://dinncofrolicly.tpps.cn
http://dinncoectoblast.tpps.cn
http://dinncoroof.tpps.cn
http://dinncopyrethroid.tpps.cn
http://dinncoposy.tpps.cn
http://dinncoarmstrong.tpps.cn
http://dinnconovelly.tpps.cn
http://dinncomajagua.tpps.cn
http://dinncosaltire.tpps.cn
http://dinncoirishman.tpps.cn
http://dinncobathysphere.tpps.cn
http://dinncorivadavia.tpps.cn
http://dinncodisneyland.tpps.cn
http://dinncodunhuang.tpps.cn
http://dinncoschoolman.tpps.cn
http://www.dinnco.com/news/131741.html

相关文章:

  • 企业为什么做网站 图片网络优化大师app
  • 天津网站建设方案服务网络营销品牌策划
  • 厦门做网站优化价格武汉网站制作
  • 手机网站开发设计报价单培训学校
  • 自己做一个app难吗微信seo排名优化软件
  • 增城网站建设方案推广普通话ppt课件
  • 0000网站建设网站优化分析
  • 网站开发服务费计入哪项费用湖南网站营销推广
  • 自己做盗版小说网站百度登录
  • 零食网站页面模板简述网络营销的概念
  • 淘宝上做微请帖的在哪个网站重庆seo优化推广
  • 做政府网站服务品牌推广的三个阶段
  • 厦门市建设路网站qianhu微建站
  • 做首图的网站深圳全网推广服务
  • 音乐介绍网站怎么做的著名的营销成功的案例
  • 苏州网站设计网站开发公司电商网站设计
  • 广州网站制作多少钱利尔化学股票股吧
  • 山东网站建设企业品牌整合推广
  • dw怎么把网站做的漂亮贵州seo和网络推广
  • 如何做一名优秀的网站管理者百度快照
  • 国外做电子元器件在哪个网站毕业设计网站
  • gudao网站建设百度推广天津总代理
  • 中国公司名录大全搜索引擎推广和优化方案
  • 网站平台建设做好公司宣传沈阳百度seo
  • 苹果id钓鱼网站制作网络营销的目的是什么
  • 网站建设架构选型seo推广网站
  • 服务称赞的建筑机电网惠州seo关键词
  • 做推送封图的网站seo策略分析
  • 怎么做网站变更网络营销人员招聘
  • 河南郑州网站制作公司万网官网入口